Looking for syntax on how to check automation variable's value to zero.
I later divide by this variable varTotalCountSmart, so need to add a condition before the math function to not execute the create variable varEpicCompletion if varTotalCountSmart is equal to 0
calculation
varTotalCountSmart
varTotalCountSmart
Without seeing your entire rule, what do you want to happen when the total count is 0?
UPDATED: please see answer in a later post to handle when it is unknown if numerator equals 0.
Let's assume you want the varEpicCompletion to be 0 also.
There are several ways to handle this, and the simplest is to use an inline condition to substitute a value when it is 0, such as 1. This could be done in either variable because if the total count is 0, the done count is also likely 0; thus 0 / 1 = 0.
{{#=}} FLOOR( {{varDoneCount}} / {{if(varTotalCount.asNumber.gt(0), varTotalCount, 1)}} * 100) {{/}}
Kind regards,
Bill
Thank you so much for this your analysis was spot on. however, the new formula, did not produce expected results when:
input:
varTotalCount = 30
varDoneCount = 5
result: Percent complete is: 500, Done Count: 5, Child Issue count: 30
expected result : Percent complete is: 16, Done Count: 5, Child Issue count: 30
it doesn't appear this is working quite right
if(varTotalCount.asNumber.gt(0), varTotalCount, 1)
true false
Seems in the first scenario I still got a false, so 5/1 = 5*100 = 500
for the scenario you were addressing the results work fine, it ran successfully and didn't give me the divide by 0 error
input:
varTotalCount = 0
varDoneCount = 0
Percent complete is: 0, Done Count: 0, Child Issue count: 0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I should have read my own post more clearly :^)
This one works for both cases, putting the default value of 0 before the long-format of conditional expression.
{{#=}} FLOOR ( 0{{#if(varTotalCount.asNumber.gt(0))}}{{varDoneCount}}/{{varTotalCount}} * 100{{/}} ){{/}}
More information...
My earlier assumption was varDoneCount will be 0 when varTotalCount is 0. To handle errors where that assumption is not valid the new expression wraps all the math inside the logical test.
And, the inline conditional version will not work as it assumes the values for "true" and "false" are text, and so cannot be fully evaluated as numbers until exiting the condition block / parentheses.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You were right from the beginning, your first answer was correct and your assumption was correct. Please keep both formulas in the final answer acceptance, as I may need the second for another problem in the future, so I wouldn't want to lose it.
The problem was the variable was actually called varTotalCountSmart not varTotalCount.
stupid me missed that, when I just pasted in the expression.
Thank you so much again for all your assistance. You have been a life saver in getting this correct.
We can accept your first answer or your second, both work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.