Jira Automation: Can't use the result of a math expression to calculate a date
Asked by Emre Toptanc? _OBSS_:

I am using Jira Automation on Jira DC 9.3.

What I am trying to do is to use the result of a math round function as a parameter of plusDays() function to set the duedate field.

(Below, I am using the value 13.2 for brevity. Actually, that value will come from another smart value, from the json of a previous REST call action.)

I tried this. This one works:
> {{now.plusHours(round(13.2, 0))}}

But since the value from the REST call json is a string, I need to add an asNumber function like this:
> {{now.plusHours(round({{asNumber}}13.2, 0))}}

When the rule runs, I get this error:
> Error rendering smart-values when executing this rule:  
> Failed to get value for now.plusHours(round({{asNumber: {{now.plusHours(round({{asNumber}}13.2, 0))}}

Then I presumed this was caused by the round function not being enclosed in math expression tags so I tried this:
> {{now.plusHours({{#=}}round({{asNumber}}13.2, 0){{/}})}}

This time I can't even publish the rule. I get the following error message while trying to publish:
> Error parsing template: Mismatched start/end tags: null != in template ....

The one below saves and executes successfully but of course, it processes the now.PlusDays() function as text and doesn't run it. It just prints it.
> now.plusHours({{#=}}round({{asNumber}}13.2, 0){{/}})

I hope someone can enlighten me about this.

Thank you

EmreT


Answers:
author: John Funk
body: Hi Emre,

You need to setup a variable and then use the value of the variable. See this other post that will guide you through that.

<https://community.atlassian.com/t5/Automation-questions/Automate-quot-Target-Date-quot-field-when-ticket-is-moved-to/qaq-p/2251838>

comments: author: Emre Toptanc? _OBSS_
body: Hello [@John Funk](/t5/user/viewprofilepage/user-id/7148) ,

We did this on the cloud platform just as you said, with a variable. But there is no *Create Variable* action on Jira DC.

Is there a workaround?

EmreT


author: John Funk
body: Oh - not sure then as I don't have a DC version. [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) - any thoughts?


author: Bill Sheboy
body: Hi [@Emre Toptanc? _OBSS_](/t5/user/viewprofilepage/user-id/527548) and [@John Funk](/t5/user/viewprofilepage/user-id/7148)

I noticed you have some extra curly brackets in the expressions...once inside of the brackets the other ones are not needed. For example:

{{now.plusHours(*someVariable*.asNumber)}}

Please note that I assumed use of a variable, and so converted from text to number type.

Next, round() has a few different syntaxes, such as {{issue.*someField* .round}} or {{#=}}round({{issue.*someField*,2){{/}}

If neither of those things help, please consider posting an image of your rule, including the details where the round() is occurring. Those may provide some context for the symptom you are observing. Thanks!

Kind regards,  
Bill


author: Emre Toptanc? _OBSS_
body: Hello [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) ,

Below is the complete smart value that we are trying to use with *Edit Issue* action to update the duedate field.
> {{now.plusDays({{#=}}round({{asNumber}}{{webhookResponse.body.table.body.rows.valueColumns.value.get(0)}}, 0){{/}})}}

As you can see, we are trying to round some value from the json result of an earlier *Send Web Request* action and add it to *now* to create a new duedate value.

It is worth emphasizing once again that we are on Jira DC 9.3 so there is no Create Variable action to use.

Thanks.

EmreT


author: Bill Sheboy
body: Thanks for that information. Perhaps trying using chained functions instead:

{{now.plusDays(webhookResponse.body.table.body.rows.valueColumns.value.get(0).asNumber.round)}}


author: Emre Toptanc? _OBSS_
body: Nope, doesn't work.

This one returns a value:
> {{webhookResponse.body.table.body.rows.valueColumns.value.get(0)}}

But when you chain an "asNumber", it returns empty:
> {{webhookResponse.body.table.body.rows.valueColumns.value.get(0).asNumber}}

You know what? I tried the same thing with original estimate field. The smart value below works for original estimate:
> {{#=}}round({{asNumber}}{{webhookResponse.body.table.body.rows.valueColumns.value.get(0)}}, 0){{/}}d

It is clear that we can do asNumber and round without a problem. But when I try to send this value to plusDays function as a parameter (as shown below), it starts complaining about mismatched start/end tags and doesn't publish the rule.
> {{now.plusDays({{#=}}round({{asNumber}}{{webhookResponse.body.table.body.rows.valueColumns.value.get(0)}}, 0){{/}})}}


author: Bill Sheboy
body: That makes sense due to the embedded bracketing. I suspect the reason the chained value does not work is typing related. Perhaps consider sending that one to the support team and ask them why it does not work for the Server/Data Center version of automation rules.


Tags: jira-server