Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

smart value for date diff not working Edited

I have been using JIRA project automation to send reminder emails. The body of the email is a table which has a colume to be the difference between created date and now. I have tried multiple combination but none are returning any values in the generated email. there is no error in the audit log either. any pointers will be appreciated. 

 

<td>{{created.diff(now).hours}}</td>
<td>{{now.diff(issue.created).abs.days}}</td>

 

Pasting the body of the email 


<p><b>Total Issue Count</b>:{{issues.size}}</p>
<b>List of Issues</b>
<table>
<tr>
<th>Issue Key</th>
<th>Created</th>
<th>Assignee</th>
<th>Status</th>
<th>Open Duration(days)</th>
<th>Open Duration(days)</th>
</tr>
{{#issues}}
<tr>
<td><a href="{{toUrl}}">{{key}} -{{summary}} </a></td>
<td>{{created.format("dd/MM/yyyy")}}</td>
<td>{{assignee.displayName}}</td>
<td>{{status.name}}</td>
<td>{{created.diff(now).hours}}</td>
<td>{{now.diff(issue.created).abs.days}}</td>
</tr>
{{/}}
</table>

1 answer

Hi @Tushar_A_ 

When I tried your smart values alone, they worked for me.  Although I would add the issue. prefix to reduce confusion for others reading the rule.

Maybe there is a problem with your table mark-up, so try to implement it piece by piece to see what is causing the problem

Best regards,

Bill

Thanks @Bill Sheboy

 

I have the other html options works, only one coming blank is this. When i add issue. it does not return any value. this is likely because of {{#issues}} that we have used. 

Will keep looking for a resolution. 

Hi, I am also experiencing this issue with the use of the diff function.  In the email body:

{{#=}}

{{issue.created.jiraDate}}
{{now.jiraDate}}
{{issue.created.diff(now).days}}

{{/}}

Results in a rule execution error with the Send Email action:

Error rendering smart-values when executing this rule:
Too many numbers or variables: 2020-04-08 2020-11-12 218

2020-04-08 is the correct created date

2020-11-12 is now

218 days is the correct days difference

Not sure what is causing the error. Any help would be appreciated.

Best regards, Bruce

Hi @Bruce MacNeil   -- Welcome to the Atlassian Community!

You are getting that error because you are using the math operations {{#=}} with multiple smart values, but not doing math with the issue values.

If you want to just do that for one issue, drop the {{#=}} and the {{/}}

If you are doing that for a list of issues, such as from Lookup Issues, then instead try something like:

{{#lookupIssues}}
* <a href="{{url}}">{{key}} - {{summary} - Created: {{created}} -- Elapsed days: {{created.diff(now).days}}</a>
{{/}}

Best regards,

Bill

Hi @William Sheboy thanks so much for your reply!

{{issue.created.diff(now).days}} by itself outputs the correct # of days

I also put a MAX() around my initial attempt, using {{#=}} it as well outputs the correct # of days:

{{#=}}
MAX({{issue.created.diff(now).days}})
{{/}}

But I get no output when I want to iterate though all issues in my JQL set of issues, this is what @Tushar_A_ had reported:

{{#issues}}
{{created.diff(now).days}}
{{/}}

I tried using {{issue.created.diff(now).days}}, same result (no output).

I do not have the Lookup Issues action available to me, I believe this might be due to the fact that I am running on Jira Data Center.  I am creating my JQL set of issues via the Scheduled trigger.

Thanks again for your help.

 

Best regards, Bruce

Bruce, would you please post an image of your complete rule?  That may help reveal where the issue is occurring. 

And, I suspect that because server and data center do not have LookupIssues or Create Variable, you may need to get creative to accumulate string values from a list (to build your email markup), perhaps using properties or custom fields in a specific issue as containers.

Thanks!

__Bill

Hi Bill, here is the rule, it is very simple for debugging purposes.  In the email body, I only have:

{{#issues}}
{{created.diff(now).days}}
{{/}}

I do get the email, with the set subject line, but nothing in the email body.

If I only have {{issue.created.diff(now).days}} in the email body, no {{#issues}} {{/}} wrapped around it, I do get a correct number of days in the the email (body) but of course only for one issue in the JQL set of issues.  My JQL set contains > 1 issue, as confirmed by Validate query.

Thanks, Bruce

ScheduledRule.JPG

Thanks, @Bruce MacNeil 

I am still experimenting with this (although in Cloud) and I believe that we have discovered two valuable things about the Scheduled Trigger, both worthy of submitting defects to support...

1) Try this in a log entry:

The number of issues is: {{issues.size}}

This returns 0 or 1, and in fact does not return the number of issues returned by the scheduled JQL, as noted in the documentation: https://confluence.atlassian.com/automation/smart-values-993924860.html

and B) Try this in a log entry:

{{now}} -- {{#issues}}* {{key}}, now: {{now}} {{/}}

This returns the value of {{now}}, followed by a list of the keys, and no values for {{now}} inside of the list structure: {{now}} does not work inside of Schedule Trigger lists.

There may still be a work-around to ponder.  As you have discovered these, I'll give you the honor of submitting the defects.  ;^)

Best regards,

Bill

The only work-around I found for open/active day count for the Scheduled Trigger's list is to:

  • Make a minor edit to each returned issue.  For example, add a space after the description field with the edit action.
  • Change your calculation to use updated rather than now: {{created.diff(updated).days}}

The context within the list's iterator only seems to recognize fields within the issues of the list.

Hi @Bill Sheboy 

I am seeing the correct {{issues.size}}, my JQL produces 2 issues, and in the log:

The number of issues is: 2

I placed {{now}} -- {{#issues}}* {{key}}, now: {{now}} {{/}} as an audit log action, and I as well see that there in no value for {{now}} when processed by the list iterator.

Using {{created.diff(updated).days}} instead of {{now}}, the correct days difference is included for both issues in my JQL set, when processed by the list iterator.

I will raise a bug / defect for the use of {{now}} in Scheduled trigger lists.

Many thanks!

Best regards, Bruce

Like Bill Sheboy likes this

Bruce, I am glad that worked for you!

I already submitted the ticket for Cloud for both, so you can submit the one for {{now}} for server.  It appears that the size() problem is only for Cloud.

Specifically for the {{now}} issue, I tested several other smart values within the scope of the iterator, and it appears that only the scheduled trigger's returned items' smart values can be used.  (Whew, that's a subtle defect!)

Have a good one,

Bill

Like Bruce MacNeil likes this

I've got the same issue when using #lookupIssues - {{now}} returns an empty string. It appears that this might be a wider defect ie. "within any list only the current item's smart values can be used." I encountered this today using Jira cloud.

For reference, my use case is almost identical to the above - automating an email to display the age of items selected via JQL:

{{#lookupIssues}}
<tr><td style="width:15%"><a href="{{url}}">{{key}}</a></td><td style="width:70%">{{summary}}</td><td style="width:15%">{{created.diff(now).days}}</td></tr>
{{/}}

At the minute I can't think of a workaround for my use case. Not many fields are made available whilst iterating in the Lookup Issues action (see https://support.atlassian.com/jira-software-cloud/docs/automation-actions/#Automationactions-Lookupissues) so it doesn't seem like it's possible to do something with custom fields.

Hi @Callum Clarke 

Yup, at this time those fields and functions are not available within Lookup Issues:

One work-around for your use case is to use a custom field and scheduled rule to compute the age, and then subscribe to a filter to get the list with the value.  We are doing something similar for Age of WIP:

https://community.atlassian.com/t5/Automation-discussions/What-is-your-most-useful-automation-Here-is-mine/m-p/1561072#M34

Best regards,

Bill

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Announcing the waitlist for Jira Work Management

Hey there Cloud Community members! We’re excited to give you the first glimpse of the new home for business teams on Jira — Jira Work Management. Jira Work Management is the next generation of J...

863 views 14 20
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you