Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Variable set in if else-if ends up null

Derek F
Contributor
February 13, 2023

Hi, I am trying to set due dates based on the Component that is set on the Story (Small, Medium, Large).  Note that I copy the Components to the sub-tasks in an attempt to simplify the logic of looking up the Components.  

I created an if else-if branch to manage these three conditions, and in each I set a variable to hold the date.

Right after the variable is set, I have a For Parent branch to create sub-tasks and assign due dates...but they are turning up blank.

So I added a test audit log entry to see if the variable existed even just after the if else-if branch ended and it doesn't.  It's already null.

I can see in the rule audit log that the condition passes successfully so why is my variable null?

thanks

 

rule1snip.PNGrule2snip.PNGrule3snip.PNG

 

1 answer

1 accepted

3 votes
Answer accepted
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2023

Is the log action within the if/else block or outside? The screenshots indicate that it is outside of the if/else block and that would explain why the variable is null. A smart value that is created with a if/else block is only available within that block and cannot be accessed outside of it.

Derek F
Contributor
February 13, 2023

Outside.  The article where they launched this feature says exactly this:

This article is for the power users of Jira automation to show you how to use our new 'Create variable' action. 

This new action allows you to define your own smart value, which can be used in other actions and conditions in the same rule. 

https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Create-variable-New-component/ba-p/1448118

 

So to me it makes no sense that it is confined to only the if else block.  Maybe they'll broaden in the future.

Like Walter Lamm likes this
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2023

It depends on where you create the variable. If you look in the article they are creating the variable first before using it in the branch. If the variable is created with the branch, you will not be able to access it outside of that branch, that's the difference.

Jeret Shuck
Contributor
February 13, 2023

I agree with Derek here. I have a similar automation where I set a variable, and need to use outside the IF block I created it in. 

I also found this: https://jira.atlassian.com/browse/AUTO-154

 

Looks like it's an active feature request.

Like Walter Lamm likes this
Derek F
Contributor
February 13, 2023

@Mikael Sandberg yes you're right -- but the value of the variable is based on which Component is tagged so I have no choice but to set it in an if/else block.  

Kelly Arrey
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 14, 2023

I haven't tried this but can you create it outside the if/else block and then set in inside?

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 14, 2023

@Kelly Arrey yes, if you create the variable outside of the if/else block it becomes a global variable and can then be used inside the if/else block. Have a look at the article above that Derek linked to.

Like Kelly Arrey likes this
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 14, 2023

@Derek F You can set the variable to null outside of the if/else block and then use it within to set it to the right value.

Like # people like this
Derek F
Contributor
February 15, 2023

I reread that a few times so...I use "create a variable" to create it before the loop and then "create a variable" again to set it to the actual value I want and use it?  

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 15, 2023

Correct, you will have to use the create a variable multiple times, but as long as you use the same name it will just update the value for the variable.

Like Steffen Opel _Utoolity_ likes this
Derek F
Contributor
February 15, 2023

Dang, I just created the a gross workaround for this (but it works).  When I'm feeling brave I'll optimize it.  Thank you

Like Kelly Arrey likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events