Forums

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

How to use a variable in a date calculation for Data Center Automation?

Jeremy Jedlicka
Contributor
July 17, 2024

 

 

I am trying to create a rule that automatically creates a set of sub-tasks when a story is created. Each Sub-task will have Target start and end dates created within the rule based off the target start and end dates of the story. For example if the story has a date difference of 90 days between the start and end dates the first sub-task will have dates that cover 10% of that, or 9 days.

I have a variable which calculates that 10%:

endDate

{{#=}}ROUND({{triggerIssue.Target start.toDate("yyyy-MM-dd").diff(triggerIssue.Target end.toDate("yyyy-MM-dd")).days*.1,0){{/}}

When I try to use this variable within a date calculation it doesn't work. When adding it to the audit log, for instance:{{now.plusDays(endDate)}}the log is empty. {{now.plusDays(endDate.asNumber)}} also doesn't work.

Does anyone know how to use a variable within a date calculation, or at the very least how to get a variable to function as a number?

2 answers

0 votes
Jeremy Jedlicka July 25, 2024

If anyone searches this in the future, I reached out to Atlassian for this, and they responded that the new syntax Automation uses cannot do this.  The old syntax can though.  Here is the JSON snippet Atlassian gave me to solve my request

 

{"fields": { 
"Target Start": "{{triggerIssue.Target Start}}",
"Target End": "{{#triggerIssue.Target Start.toDate}}func=plusBusinessDays({{endDate}}){{/}}"
}
}

 JSON 

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.
July 25, 2024

Thanks for that information, Jeremy.

Did the support team indicate if this was a behavior of Jira Data Center automation rules or something else? 

And what did they mean by "new syntax Automation"?

Jeremy Jedlicka July 25, 2024

The syntax automation uses for Smart values apparently changed when Atlassian acquired Automation.  I asked for documentation of the old syntax, but they said they didn't have any publicly available. 

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.
July 25, 2024

Yup...they took down / removed public access to the old Codebarrel blog, documentation, and backlog some time after the Atlassian documentation pages went live.

0 votes
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.
July 18, 2024

Hi @Jeremy Jedlicka 

Your expression to perform the date difference is missing the closing double-curly brackets }}

{{#=}}ROUND({{triggerIssue.Target start.toDate("yyyy-MM-dd").diff(triggerIssue.Target end.toDate("yyyy-MM-dd")).days}}*0.1,0){{/}}

When writing expressions like this, you may want to create them in a text editor which highlights matching brackets, parentheses, etc. in order to see them more easily.  Then copy-and-paste them into the rule editor.

 

Next, created variables are text, and to use them as numbers you may add the asNumber conversion:

{{varMyVariable.asNumber}}

 

Kind regards,
Bill

Jeremy Jedlicka
Contributor
July 18, 2024

My variable does have the closing }}. that was a transcription error.

 

The {{endDate.asNumber}} produces a null value instead of number as it should based off the documentation here: 

 

Automation smart values - text fields | Cloud automation Cloud | Atlassian Support

it seems trying to convert a variable to a number isn't possible. 

Even changing the variable to just be the number 9 and trying to add

{{now.plusDays({{endDate.asNumber}})}}

results in the error: Failed to get value.

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.
July 18, 2024

When inside a set of double-curly brackets, another set is not needed.  Please try this:

{{now.plusDays(endDate.asNumber)}}

 

If that also does not help...

Please post an image of your complete automation rule and an image of the audit log details showing your rule execution.  Those will provide context and may help explain what you are observing.

 

And, you appear to be using Jira Data Center.  I recommend writing the following to the audit log to confirm the smart values contain what you expect:

Target start       : {{triggerIssue.Target start}}

Target start toDate: {{triggerIssue.Target start.toDate("yyyy-MM-dd")}}

Target end : {{triggerIssue.Target end}}

Target end toDate: {{triggerIssue.Target end.toDate("yyyy-MM-dd")}}

diff value : {{triggerIssue.Target start.toDate("yyyy-MM-dd").diff(triggerIssue.Target end.toDate("yyyy-MM-dd")).days}}

 

Jeremy Jedlicka
Contributor
July 24, 2024

the suggestion:

{{now.plusDays(endDate.asNumber)}}

also produces a null value.

What's odd is that:

{{#if(endDate.asNumber.isEmpty)}}EMPTY{{/}} {{#if(not(endDate.asNumber.isEmpty))}}NOT EMPTY{{/}}

Returns NOT EMPTY, so there is something coming though - it's just not being shown in the audit log and it doesn't work in a date calculation.

 

I can't provide screenshots because our Jira is on a separate classified network not connected to the internt.

 

Suggest an answer

Log in or Sign up to answer