Hi,
Hoping someone else has come across this scenario with Automation for JIRA.
I'm trying to perform a simple addition of numbers using an Edit action:
{{issue.customfield_12143}} + {{issue.customfield_12144}}
This works, but only if both customfields have values (aren't empty). Otherwise, I get errors:
Could not convert the field value to a number. Please ensure the value is a number, math expression or smart-value that can be converted into a number.
Some Number Field: +
I also tried setting default values in the calculation, but didn't seem to help:
{{issue.customfield_12143|0}} + {{issue.customfield_12144|0}}
Any thoughts? All fields are plain old number fields.
TM
Our production is 4.2.3, but I just upgraded out test instance to 5.1.4 and same result.
I worked around it by basically checking if each field used in the calculation is empty and setting to 0. Just seems clunky.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Timothy,
Were you wrapping this operation with the maths operator?
{{#=}}{{issue.customfield_12143|0}} + {{issue.customfield_12144|0}}{{/}}
Cheers,
Simeon [Automation for Jira]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Whereabouts on https://docs.automationforjira.com/working-with-issue-data/math-functions.html#where-to-use is this
field|0
explained? I understand but searched for NULL and lots of other things before finding this community question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm assuming it will solve this error:
Could not convert the field value to a number. Please ensure the value is a number, math expression or smart-value that can be converted into a number.
Total: 1038.46 +
^ note no value at the end because my custom field value was NULL.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Martin,
Yes, it should help you out with that issue!
Cheers,
Simeon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Martin,
For the record, my problem was never resolved. I just worked around it and moved on to other things! I was basing this off the Default Values functionality: https://docs.automationforjira.com/working-with-issue-data/smart-values.html#default-values
It's worked for text values in other situations, but I couldn't get it working with math operations. Not even wrapping it with the maths operator like Simeon suggested.
My workaround was breaking apart the operation into multiple automation steps, like:
And you could optionally wipe FieldA and FieldB if you didn't actually want the 0 value and have them show up on view screens, etc.
TM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@[deleted] - I actually did a quick test again and seems like the same thing is working now. We're on version 5.1.12. Were there any changes made since 5.1.4?
I literally enabled the old broken automation job (+ disabled the workaround one I made) and it worked under exactly the same circumstance that previously got an error. Either way, I guess it's behaving as expected now!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Timothy,
Not that I know of that would have affect this behaviour. It should have been included in 5.1.4, glad it is working for you though!
Cheers,
Simeon.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I posted my solution in a more recent thread that asks the same question. I will repost my solution here, but the details are in the other post.
My solution, uses the IF mathematical expression - IF(condition,value_if_true,value_if_false) instead of using {{field|0}}.
{{#=}}
{{IF(issue.customfield_13400,issue.customfield_13400,0)}}
+ {{IF(issue.customfield_13401,issue.customfield_13401,0)}}
{{/}}
It's not pretty but the above works, because the mathematical IF(,,0) always return a true numeric zero.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For anyone who comes across this and doesn't understand why there's isn't working, this feature is sensitive to spaces
{{variable| 0}}
behaves as expected
{{variable | 0}}
always returns 0 (note the space between the variable and the vertical line)
I'm not sure if this is intended behavior, but it made for a frustrating morning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.