Maths with empty fields

Tim Martin February 8, 2019

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

3 answers

1 accepted

1 vote
Answer accepted
Deleted user February 10, 2019

Hi Timothy,

I'm surprised that the default isn't working for you. What version of Automation for Jira are you using?

Cheers,
Simeon [Automation for Jira]

Tim Martin February 14, 2019

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.

 

Deleted user February 17, 2019

Hi Timothy,

Were you wrapping this operation with the maths operator?

{{#=}}{{issue.customfield_12143|0}} + {{issue.customfield_12144|0}}{{/}}

Cheers,

Simeon [Automation for Jira]

Like Dave Sausville likes this
Martin Cleaver
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.
April 29, 2019

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.

Martin Cleaver
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.
April 29, 2019

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.

Deleted user April 29, 2019

Hi Martin,

Yes, it should help you out with that issue!

Cheers,
Simeon

Tim Martin April 29, 2019

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:

  • If: matches {{FieldA}} equals Empty
    • Edit {{FieldA}}: 0
  • If: matches {{FieldB}} equals Empty
    • Edit {{FieldB}}: 0
  • Re-fetch Issue
  • Edit {{FieldC}}: {{FieldA}} + {{FieldB}}

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

Like Martin Cleaver likes this
Tim Martin April 29, 2019

@[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!

Like Martin Cleaver likes this
Deleted user April 29, 2019

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.

Like Martin Cleaver likes this
0 votes
Johnny Mon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 26, 2023

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.  

 

0 votes
Andrew Burkett December 10, 2020

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 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events