Forums

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

How do math with values of variables through automation?

Sreelal CS
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 22, 2023

I would like to automate a calculation through automation rule.

Here, I have a task having custom field = X (numeric)

X= (A+B)/C, where

A&C= custom field of Task

B= sum of custom fields of child of Task

Here, A&C are numeric values and B is calculated value created through app. 

Now, B is not a field (only used for calculation purpose)

Option1 - Solution I have tried (didn't work):

  1. Created B as a field in Task
  2. Automated (A+B) and stored as variable x -  {{customfield_12345.Plus(customfield_23456)}}
  3. then x is divided by C and stored as variable y - {{x.divide(customfield_34567)}}
  4. display y in field X {{y}}

X.JPG

The rule run successfully. But no output as such.

Option 2 - The solution worked:

  1. Created B as a field in Task
  2. Created field D to get A+B (automation)
  3. X=D/C (automation)

 

Is there a way if I can go with option 1 without creating field B?

2 answers

1 vote
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.
December 22, 2023

Hi @Sreelal CS 

Created variables are text strings and so they usually need to be converted to numbers for use in math expressions: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#asNumber

For your example of a variable named "x" divided by a number custom field, customfield_34567:

{{x.asNumber.divide(customfield_34567)}}

 

Kind regards,
Bill

0 votes
Yi Meng
Contributor
March 3, 2025

Hi @Bill Sheboy 

I created 2 variables in Jira automation. One is {{WIPnumber}} and the other is {{All}}

I converted them using asNumber to divide them and I want to update the result in a number field. 

My formula is like

{{WIPnumber.asNumber.divide(All.asNumber)}}

But the result is always 0. At the same time, I update custom fields with these variables and it works fine. And I use the value of these custom fields to do the math, it also works fine. 

Below is how I edit my custom field value.

{{issue.customfield_10035.divide(issue.customfield_10034)}}*100

 Does it mean I can't calculate 2 variables even I converted them to numbers? Thanks,

 

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.
March 3, 2025

Hi @Yi Meng 

First thing, this is a very old thread, and so I recommend creating new questions for such cases, and perhaps adding a link back to the older one for context.  That will ensure the maximum number of people see it to offer suggestions.

 

Next, when a created variable is converted with asNumber for inline math expressions, the type (integer or floating-point) is preserved from left-to-the-right.  And so if your WIPnumber variable is an integer, the division will be integer-based, truncating any decimal digits.

To get a floating-point result, use the long-format of math expression:

{{#=}}{{WIPnumber}} / {{All}}{{/}}

You may add the ROUND() function when you want to manage the precision of the result.

 

To learn a lot more detail about using created variables as numbers, please see this recent article I wrote on the topic:

https://community.atlassian.com/t5/Automation-articles/Automation-concepts-Using-Created-Variables-as-Numbers/ba-p/2953116

 

Kind regards,
Bill

Yi Meng
Contributor
March 4, 2025

Thank you @Bill Sheboy  This works.

 

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