Order of operations when doing math to set a field value

Jeremy Steuhl
Contributor
June 7, 2023

I have a project I use to track my vehicle maintenance and fuel logs.  I'm trying to automate my fuel milage "MPG".

 

I have 3 custom numeric fields:

issue.customfield_10216 = Current Mileage ie 31,796 miles

issue.customfield_10215 = Previous Mileage ie 31,271 miles

issue.customfield_10213 = Gallons 33.5 gallons of fuel 

 

In something like excel, I'd have a formula:  (issue.customfield_10216-issue.customfield_10215)/issue.customfield_10213

 

which would result in 15.7 MPG.

 

Looking at documentation, I'm able to get the first part to work by subtracting issue.customfield_10215 from issue.customfield_10216 resulting in 525, but when I try to divide that by issue.customfield_10213 it just sets the field to 525, instead of doing the division, almost like it's ignoring the rest of my formula.

 

Here's my formula:  {{issue.customfield_10216.minus(issue.customfield_10215).divide(issue.customfield_10213)}}

I tried wrapping the first part in () like this, but that just ended up in error:

{{(issue.customfield_10216.minus(issue.customfield_10215)).divide(issue.customfield_10213)}}

 

Any suggestions on how to write this properly?

 

1 answer

1 accepted

0 votes
Answer accepted
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 7, 2023

Hello @Jeremy Steuhl 

First I recommend that you use the Log action in your rule to print to the rule's Audit Log the value of each of those custom fields to ensure the values used in the calculation are what you think they are.

I tried your math using just Log actions to see the results. First I printed the three values. Then I printed just the .minus operation. Then I printed the full math function. Oddly the results ended up in the wrong order in the log file, but the final full match function result was correct.

Screen Shot 2023-06-07 at 5.55.03 PM.png

Jeremy Steuhl
Contributor
June 8, 2023

Thanks.  Can post a screen shot(s) of the rule as you set it up?  You said you used my formula but when I use it, I don't get the right answer.  Also, I'm not familiar with using the log action in a rule.  I'm not sure based on the documentation how to enable that.  I'm hoping your screenshot(s) will answer that for me. :)

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 9, 2023

I was using whatever number fields were available so my fields compared to your fields are

Yours  Mine 
 issue.customfield_10216 Story Points 
 issue.customfield_10215 Custom Story Points Number 
 issue.customfield_10213 SK Only Number Field

Screen Shot 2023-06-09 at 9.54.56 AM.png

 

Screen Shot 2023-06-09 at 9.57.12 AM.png

Jeremy Steuhl
Contributor
June 9, 2023

Thank you so much.  Adding values to the audit log helped me solve the issue.  The problem I was having in my formula was that I transposed a few numbers, so the formula was working, but it wasn't using the right field. 

 

 

I was using issue.customfield_10213

when the field was actually issue.customfield_10123.  

 

Putting everything in the audit log showed me that and now it works.

Like Trudy Claspill likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events