Forums

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

Assigning different values to the same variable with conditions in Jira Automations

Ylan Muller
Contributor
August 7, 2024

I would like to create a variable in a Jira Automation where, based on the values of a smart value, the variable value changes. For example:

1. Create a variable called "laptop_model"

2. If "department" field value == "Engineering" set "laptop_model" to "X"

3. Else, set "laptop_model" to "Y"

4. Use the value of "laptop_model" to populate a field in a "Create Issue" step later in the flow

Is this possible to do? The issue I am having is that the only action I can seem to take for a variable is to create one - I can't edit the value to be used further down in the flow, at least not based on what I've seen. Thanks!

1 answer

1 accepted

1 vote
Answer accepted
Mikael Sandberg
Community Champion
August 7, 2024

Hi @Ylan Muller,

Welcome to Atlassian Community!

Yes, this is possible, and what you want to do is create a global smart value that is set outside of the if/else branch, you can then reuse that smart value in the if/else to give it different values. Check out this article for more information. 

Ylan Muller
Contributor
August 7, 2024

Thanks @Mikael Sandberg - very cool to know that you can use the Create Variable step to modify the value down a branch. I tested this and it looks like it also persists the output from the branch to use in steps outside of the branch as well, which solves my problem!

Like Mikael Sandberg 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.
August 8, 2024

Hi @Ylan Muller -- Welcome to the Atlassian Community!

Regarding that linked article and create variable scoping, I want to clarify the behavior for branches versus if / else rule structures.  This may prevent some rule errors in the future.

 

When a variable is re-created with same name, it does replace (i.e., shadow) the value, but only in two cases:

  • variable is created before, and then re-created within an if / else condition
  • variable is created before, and then re-created within a branch which is on one-and-only-one issue

Branches which are on one-and-only-one issue are converted to run inline, as if there was no branching.  This is the "trick" that article uses, but which it does not fully describe.

Branches which could be on more than one issue (or advanced branches), run in parallel and asynchronously.  And so each created variable within the branch is new, and thrown away when the loop item finishes processing.  And because the branch runs asynchronously, it may not be done up until the very last step of the rule; thus it could not be relied upon to have an updated value after the branch.

 

Kind regards,
Bill

Ylan Muller
Contributor
August 9, 2024

Hi @Bill Sheboy - thank you for this detail. For my automation purposes I am using two different if/else conditions - one to set the laptopModel variable, and the other that creates tickets that use the output of the laptopModel variable from the first condition. In testing this works well, but good to know that advanced branching on multiple issues would not work for this. 

 

Suggest an answer

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

Atlassian Community Events