Forums

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

Jira Automation Using Variables

Madar_ Andrew
Contributor
May 20, 2024

If I want to add 20 percent to a custom field, what is the proper syntax to do this using variables?

variable name = valueA

smart value = {{#=}}{{customfield1}} + {{customfield2}}{{/}}

 

variable name = var1

smart value = {{#=}}{{valueA}} * .20{{/}}

 

edit issue and assign value to it fieldB

{{#=}}{{valueA}} + {{var1}}{{/}}

 

The value in fieldB is not what I would expect.  Is there something wrong with the syntax of the expressions?

1 answer

1 accepted

1 vote
Answer accepted
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.
May 20, 2024

Hi @Madar_ Andrew 

For a question like this, please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected.  Those will provide context for the community to offer ideas.  Thanks!

Until we see those...

Let's assume your original customfield1 and customfield2 are both numeric.  If so, your expression could use an inline math expression like this:

{{issue.customfield1.plus(issue.customfield2).multiply(1.2)}}

If your fields are not numeric, what type are they?

Have you tried writing the values to the audit log to confirm they contain what you expect before editing the issue field, "fieldB"?

Kind regards,
Bill

Madar_ Andrew
Contributor
May 21, 2024 edited

This works great what you provided.  I used this approach for some other rules I created.  I did not see the syntax you noted using "plus" or "multiply" in the formula before.  That is good to know for future use.  Thank you!

Like • Bill Sheboy likes this
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.
May 21, 2024

Awesome; I am glad to learn that helped!

There are at least three math expression formats I know of for rules.  Learning these can help when operations do not seem to work as expected.

  1. the inline one works for number fields and static fields (not stored in lists or from rule calls outward)
  2. the longer form of {{#=}} math stuff here {{/} helps with automagically converting some text to numbers and with some list operations
  3. math expressions with no smart value wrappers some times work directly in a field

For some list and dynamic fields, occasionally the values need to be stored in a Created Variable smart value first, and then used in the math expression.

Like • Svitlana Schallert likes this

Suggest an answer

Log in or Sign up to answer