Forums

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

Automation for Jira, accessing a variable from outside of a branch

Jeffrey Bistrong
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.
February 8, 2023

I am not sure if this is intended or it is a bug, but I wanted to share and see what others think. 

 

I am trying to create a variable inside of a branched JQL lookup and then use that variable outside of the branch.

 

Referring to my below screen shots, I was trying to access Variable A in the "Advanced Edit" at the bottom of the automation rule (which was located outside of the branched rule.

You can see in box #1, logging the action produced no result.

 

However, when I added Variable B (at the top) before the branched rule, it then changed something which then allowed me to access variable A outside of the automation rule (refer to box 2) which shows the log action. 

Monosnap Automation - JIRA 2023-02-08 16-26-28.png

 

Below are screen shots of the entire automation rule if anyone wants to see what I am doing. The custom field 10800 is the Teams field that comes from Advanced Roadmaps, and has limited functionality inside of the automation tool, so I must manually manipulate it. 

1.png2.png3.png4.png

1 answer

2 votes
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.
February 8, 2023

Hi @Jeffrey Bistrong 

TL;DR: the variable goes out of scope because of how branches work, and so is null.

Apologies in advance...I tried to write a shorter answer for this and was unable to do so.  :^)

Branches which can only be on one-and-only one issue (e.g. on Parent, on Current Issue, etc.) are actually run in-line.  And so it is like the branch did not exist (except to help with conditions).

Branches which could be on more than one issue (e.g. JQL, linked issues, etc.) are run in parallel and asynchronously.  And so...there is no guarantee of when the branch will finish, until right up to the end of the rule.  Stuff that happens inside these branches remains so, except for any issue updates, web requests, etc.

Putting these things together, let's look at an example:

  • trigger: some trigger which has an issue
  • action: create variable named varBeforeBranch
  • branch: on Current issue
    • inside...varBeforeBranch as a value
    • action: create variable named varInsideOneIssueBranch
  • outside of the branch...varBeforeBranch and varInsideOneIssueBranch have values
  • branch: on some JQL
    • inside...varBeforeBranch and varInsideOneIssueBranch have values
    • action: create variable named varInsideTwoIssueBranch
  • outside of the branch...varInsideTwoIssueBranch has no meaning and so is null

 

The original community post on create variable, which I cannot find, showed an example where a variable was created before and then inside a branch, and successfully used later.  That was a bit misleading as the branch was a one-and-only one issue type.

Often work-arounds for this design need are to rethink what you are trying to capture and use divide-and-conquer (with multiple rules) or lookup issues/objects to sum, average, etc. the data.

Kind regards,
Bill

Chiranjib B May 23, 2023

Hey @Bill Sheboy 

Were you referring to this example, that you consider misleading?

My use-case is, I want to aggregate efforts logged by each team (hence branching out once for each team) and then compile them into a confluence document (using the custom web request action)

I am failing to propagate the desired info as I desire, would you have any suggestions for me?

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 23, 2023

Hi @Chiranjib B 

Yes, that is one of the examples.

For your use case, perhaps one of these approaches would work:

  1. advanced branch on your different teams list; use a lookup issues action to gather the information you want on the Confluence page call the web request for the Confluence page
  2. lookup issues to gather the information needed; use if/else structures for each team, and smart value filtering to gather the results needed; add a single condition to test for presence of the data, and then call the web request for the Confluence page change/create

Kind regards,
Bill

Marc Isikoff
Contributor
June 21, 2024

If I am reading this correctly, we can branch on current issue, create a variable in th branch using JQL to ensure it has a singular value, and then use that variable within the branch and should be fine.

Meaning if we can guarantee we are getting one epic (I am trying to find a key for a single Epic and assign that to the issue as the epic link) it should be possible?

Bentley, Andrea January 14, 2025

I know this is an old question, but I think I have the answer. Any variable created within an IF Branch or a FOR Branch will not be in scope outside of the branch. However, if you create the variable at the very beginning and give it a default value, you can then give it a new value within your branches, and it will be in scope anywhere in the automation.

Jira-Automation-Variable-Global.jpgJira-Automation-Variable-In-Branch.jpg

When I run the automation and check the audit log, the value of myVar is the value set in the branch.

Like Siree Chambers likes this
Siree Chambers
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!
April 21, 2025

Brilliant Andrea! That works beautifully!

Like Bentley, Andrea likes 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