Hello.
In a scheduled automation, I am trying to calculate the difference between the current day and the Target Start day. The automation runs successfully, but the variable that I am trying to put the value into is blank. Any suggestions? Here is the Smart Value I am using:
{{issue.Target Start.diff(now)}}
I have confirmed that I can move both values (issue.Target Start and now) into variables successfully. I've also tried to use those variables as a work around but no luck there.
Any ideas are greatly appreciated!
Hello @Kevin Wujcik
Welcome to the Atlassian community.
Can you please provide screen images showing the entire automation rule?
What is the field type for Target Start? Is it a Date field, Date/Time field, or something else?
One thing that I notice is that you did not specify the unit for output. Do you want weeks, days, hours, ...?
{{[date1].diff([date2]).[unit]}}
Try adding the unit to the smart value and see if that improves your results.
I'm looking for the field definition for Target Start, but it is the default field type used by Advanced Roadmaps.
Good catch on the unit. I updated accordingly and unfortunately still no luck there ({{issue.Target Start.diff(now).days}}). Same results.
Does this give you what you were looking for?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I found the answer here:
Though that article says it is applicable to Data Center the same solution works for Cloud.
Try this:
{{issue.Target Start.toDate("yyyy-MM-dd")
.diff(now)}}
I tried that in my own system and it worked.
Also make sure that "Target Start" is the proper name for the field. In my system it is "Target start" with a lower case "s". Automation rule references to field names can be case sensitive.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like that was it! Thank you so much for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Kevin Wujcik -- Welcome to the Atlassian Community!
The built-in Target Start and Target End fields' values provided to rules are text representing a date value. They cannot be used with the diff() function until they are converted with toDate:
For example:
{{issue.Target start.toDate.diff(now).days}}
(Although you may want to reverse the values if the target is in the future.)
And if you want to set the value of the target fields, I believe that must be done using a JSON expression.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kevin!
The issue is likely with the field name format and .diff()
method syntax. Try these solutions:
1. Field name format: Custom fields with spaces need quotes or underscores:
{{issue."Target Start".diff(now)}}
or
{{issue.customfield_XXXXX.diff(now)}}
2. Check the diff() method: The .diff()
method returns milliseconds by default. Try:
{{issue."Target Start".diff(now).dividedBy(86400000)}}
(This converts to days)
3. Alternative approach:
{{now.diff(issue."Target Start").dividedBy(86400000)}}
(This gives positive numbers for past dates)
4. For debugging: Add this to see what's actually in your field:
Target Start: {{issue."Target Start"}}
Now: {{now}}
Diff: {{issue."Target Start".diff(now)}}
5. Date format check: Make sure your "Target Start" field is actually a date/datetime field type, not text.
Try these and let me know what you see!
Best, Vitaliy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the suggestions, Vitalii. Trudy's answer above worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.