Forums

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

Variable wont get calculated

Marcel Varsa February 15, 2024

I have following command to calculate variable {{KMProgress}} as a percentage of count of done items divided by the total count of items: ({{KMDoneCount}}/({{KMTotalCount}})*100)

Both of the variables are {{lookupIssues.size|0}} of different JQL's - first returning 1 done item and second returning 10 items in total

When I run the automation and call {{KMProgress}} to be send by email this is the result I get: (1/(10)*100)

Can someone explain/help why it is not counting/returning that progress is 10% but instead returning a text?

Thanx

3 answers

1 accepted

3 votes
Answer accepted
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.
February 15, 2024

Hi @Marcel Varsa 

For a question like this, please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected.  Those will provide context for the community to offer ideas.  Thanks!

Until we see those...

Created variables are text, not other types, like numbers.  To use a created variable in a math expression it usually must be converted with asNumber.  For example:

{{KMDoneCount.asNumber}}

What you saw was the text values concatenated together as they were not numbers.

 

Next, there are two formats for math expressions: inline and the longer format: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/

What you plan to do with the result may help decide which format to use.  For example, the inline format of your formula could be this:

{{KMDoneCount.asNumber.divide(KMTotalCount.asNumber).multiply(100)}}

This will not handle empty fields / variables, but that should not be needed as you are using the default value of 0 with your lookup expression: {{lookupIssues.size|0}}

Additional tip: as you appear to trying to produce a percentage value, consider adding the asPercentage function or using floor or ceil (i.e., ceiling) to limit the result digits.

 

Kind regards,
Bill

Marcel Varsa February 15, 2024

Hi @Bill Sheboy

 

Sure, here is the whole automation rule picture:

aut rule.PNG

 

I have used suggested command below, this time the result was 0

{{KMDoneCount.asNumber.divide(KMTotalCount.asNumber).multiply(100)}}

 

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.
February 15, 2024

Please show the details of the actions to set the values of the variables.

Please post an image of the audit log showing the rule execution.  That will indicate if there were problems with any of the rule steps.

 

Does your rule trigger include any JQL?  For this type of rule, I would not expect it to have any.

 

Have you tried writing the variables to the audit log to confirm they have values, as you expected?

 

Like Uday Kiran Bhaviri likes this
Marcel Varsa February 15, 2024

Variable KMTotalCount:

kmtotal.PNG

 

Variable KM DoneCount:

kmdone.PNG

 

Variable KMProgress:
kmprogress.PNG

Thank just calling it all in the mail:

mail.PNG

 

According to info in audit log, it seems to me that I am pulling the issues I want to pull

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.
February 15, 2024

Thanks for that information.

Did you try writing each created variable to the audit log to confirm their values?

Marcel Varsa February 15, 2024

@Bill Sheboy I tried to investigate audit log, this is the only thing I see there:

audit.PNG

 

And these are the items I am looking for - so not sure why I am not getting the calculation correctly.

 

Other interesting thing is that if I swap the formula it returns the number it is supposed to return: {{KMTotalCount.asNumber.divide(KMDoneCount.asNumber)}}, the other way around I always get 0.

Any ideas why it happens when I am dividing smaller number with higher it does not work?

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.
February 15, 2024

This uncertainty is why I asked for an audit logging of each individual created variable: 

{{KMTotalCount}}
{{KMDoneCount}}
etc.

That would first confirm the counts (and thus the lookups and JQL) worked as you expected, before using them in math operations.

Marcel Varsa February 16, 2024

Really no clue what can be the issue so taking step back.

The need is to send report every week showing the "progress" on Initiative (backlog hierarchy is Initiative - Epic - Story).

I would like to show the progress by taking the done child items under the initiative (epics and stories) and divide them by total number of items under initiatives (epics and stories).  Final number multiply by 100 to get the result in %.

How would you approach that automation?

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.
February 16, 2024

As you want to count issues, from the initiative and downward, I believe you on the correct path with the lookup issues usage.  And creating each piece incrementally in variables is a good way to validate what you are doing.

It is possible to perform this calculation in a single step, using list filtering, but that is difficult to maintain. 

Instead let's stick with your approach and create a new test rule to diagnose this:

  • trigger: scheduled, with no JQL
  • action: lookup issues, which JQL to find the children of the Initiative, excluding the Initiative itself from the results
    • project = NLC AND issuekey IN portfolioChildIssuesOf("NLC-3968") AND key != NLC-3968
  • action: create variable
    • variable name: varTotalIssueCount
    • smart value: {{lookupIssues.size|0}}
  • action: log this value
    • the total issue count = {{varTotalIssueCount}}

 

  • action: lookup issues, which JQL to find the Done children of the Initiative, excluding the Initiative itself from the results
    • project = NLC AND issuekey IN portfolioChildIssuesOf("NLC-3968") AND key != NLC-3968 AND statusCategory = Done
  • action: create variable
    • variable name: varDoneIssueCount
    • smart value: {{lookupIssues.size|0}}
  • action: log this value
    • the done issue count = {{varDoneIssueCount}}

 

Now pause and test that rule by running it manually from the top-right of the editor ... > Run Rule and look at the audit log.

Do the results match what you expect for the counts?

Marcel Varsa February 16, 2024

Yeah, once I redefined the variables it it started to return numbers instead of text.

Thank you very much for your help!

Like Bill Sheboy likes this
0 votes
Marcel Varsa February 15, 2024

 

 

 

0 votes
Uday Kiran Bhaviri
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.
February 15, 2024

It should be ((1/10)*100)

For mathematical calculations just follow the below article

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/

Marcel Varsa February 15, 2024

Even with updated it still returns only text (Current progress is ((1/10)*100))

What I need it to return is number (Current progress is 10)

Uday Kiran Bhaviri
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.
February 15, 2024

Not sure how the variables were set in the automation to get the count, log them for further troubleshooting.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events