Jira automation - how do I make my math expression conditional

Ian Rees July 15, 2022

I have an automation statement where I am working out % complete and this rolls up to show %complete in the parent Epic.   It all works ok but occassionally, the child issues in the Epics have no Story Points and therefore I get a divide by 0 error.  I've been trying to use IF to make this conditional so that if varTotalStoryPoints.asNumber is zero, I just assign 0 to the variable and avoid the divide by zero error but I just cant get the syntax right - can anybody help please ?

{{#=}} {{varStoryPointsComplete.asNumber}} / {{varTotalStoryPoints.asNumber}} * 100 {{/}}

3 answers

0 votes
Stanley, Rob July 22, 2022

Hi @Ian Rees

Try using the smart value math expressions - Functions :

{{#=}} IF({{varTotalStoryPoints.asNumber}} > 0,{{varStoryPointsComplete.asNumber}}/{{varTotalStoryPoints.asNumber}}*100,0) {{/}}.

You might want to consider using asPercentage  (also with a locale option) when formatting for display to avoid having to do the * 100.

Ian Rees August 16, 2022

Hi @Stanley, Rob that's the syntax I've been trying but can't seem to get it right - for instance {{#=}} IF({{varTotalStoryPoints.asNumber}} > 0,{{varStoryPointsComplete.asNumber}}/{{varTotalStoryPoints.asNumber}}*100,0) {{/}}.

 

gives unexpected comma error

Ian Rees August 16, 2022

This worked for me is stopping the divide by zero error

{{#=}} IF({{varTotalStoryPoints.asNumber.eq(0)}},0,{{varStoryPointsComplete.asNumber}} / {{varTotalStoryPoints.asNumber}} * 100){{/}}

0 votes
Gideon Nolte [Jodocus]
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 15, 2022

Hi @Ian Rees

Just wrap your "Edit Issue"-Action inside an if-else block with an "Advanced Compare"-Condition which checks whether {{varTotalStoryPoints.asNumber}} is 0. If it is: "Edit Issue"-Action -> Set field to 0, else "Edit Issue"-Action -> Set field to MathExpression.

Final section should look something like this:

Webaufnahme_15-7-2022_15231_demo-jodocus.atlassian.net.jpeg

Note: Change Description to the field you want to edit. First Edit sets the field to 0 - Second edit sets the field to the expression.

 

Hope this helps. Feel free to reach out if there are any problems with this.

 

Greetings

Gideon

0 votes
Gaurav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 15, 2022

Hello @Ian Rees 

For this automation, the 'If Else' construct would be required. From the available details, I understand that you are storing the Total Story Points and Story Points Complete in variables.

So, when we select the If clause, opt for the 'Advanced compare condition'. The settings should be:

  • First value should be set as 'varTotalStoryPoints.asNumber'
  • The second value should be 0
  • Condition 'equals'

I hope this helps set up the IF condition. Please reach you if you have any follow-up questions.

Kindly accept the answer if this helps.

Regards,

--GG

Suggest an answer

Log in or Sign up to answer