Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

smart value for date diff not working

Tushar A. June 11, 2020

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

1 vote
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2020

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

Tushar A. June 19, 2020

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. 

Bruce MacNeil November 12, 2020

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

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 12, 2020

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

Bruce MacNeil November 13, 2020

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

Like manus likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2020

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

Bruce MacNeil November 13, 2020

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

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2020

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

Like manus likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2020

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.

Bruce MacNeil November 13, 2020

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 # people like this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2020

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
Deleted user March 4, 2021

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.

Like manus likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2021

Hi @[deleted] 

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

Like manus likes this
Dileep Kumar Simhadri
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 8, 2023

Please try now() (with parentheses) and it should work. I tried with the smartvalue: {{sprint.endDate.diff(now()).days.abs}} and it worked.

Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 9, 2023

Thanks, @Dileep Kumar Simhadri 

It seems various functions, when used in smart value parsing, are a bit inconsistent in regarding when the parentheses work / don't work.  Sometimes the expressions appear to collapse to null values instead.

Suggest an answer

Log in or Sign up to answer