Forums

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

How to create a smart variable with conditional value?

Yuliyan Serbezki August 19, 2024

Is there something similar to a switch statement in Jira Automation?

I would like to have a variable called env which has a different value depending on the status of the ticket. Something like if status equals this then env equals that, but I'm not sure what's the best way to do it. I then want to send a web request where that value will be used in the body.

I've tried defining it inline in the body, something like "env": "{{#if(equals(issue.status.name, "TRIGGER DEV DEPLOYMENT"))}}dev{{/}}{{#if(equals(issue.status.name, "TRIGGER INT DEPLOYMENT"))}}int{{/}}{{#if(equals(issue.status.name, "TRIGGER STG DEPLOYMENT"))}}stg{{/}}{{#if(equals(issue.status.name, "TRIGGER PRODEU DEPLOYMENT"))}}prodeu{{/}}{{#if(equals(issue.status.name, "TRIGGER PRODUS DEPLOYMENT"))}}produs{{/}}", but that didn't work. 

I then tried to create the smart value in a separate variable step with the same value as above - that didn't work either. 

I then tried to create a separate if status equals block then assign value step for each of these, but that also didn't work. It didn't work even when I tried to assign the var outside of all if statements. What can I be doing wrong?

6 answers

2 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
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.
August 20, 2024

Hi @Yuliyan Serbezki -- Welcome to the Atlassian Community!

Rather than using created variables or an if / else structure to solve this, I recommend using Lookup Tables.  That would be easier to maintain and collapse the rule structure to only a couple of steps, making it much easier to read / understand the rule.

To learn more about Lookup Tables, please see this article:

https://community.atlassian.com/t5/Automation-articles/Update-Create-lookup-table-action-improvements/ba-p/2427798

Kind regards,
Bill

Yuliyan Serbezki August 20, 2024

Thanks Bill! That definitely looks tidier - that's what I was hoping for when I started. 

Like Bill Sheboy likes this
Frederik Strøm Friborg January 15, 2025

Hi @Bill Sheboy

What about if you use Jira Service Management Data Center, v. 9.12.12? Lookup tables are not available there, any suggestions? :i

How-to-wait-until-end-of-automation 

Best,
Fred

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.
January 15, 2025

Hi @Frederik Strøm Friborg -- Welcome to the Atlassian Community!

I have not seen any suggestions or updates on adding Lookup Tables to Data Center automation in over a year: https://community.atlassian.com/t5/Automation-articles/Update-Create-lookup-table-action-improvements/ba-p/2427798#M966

Without those, long blocks of if / else or complicated conditional expressions are required, depending on the specifics for the scenario.  I will take a look at your other question to learn more.

Kind regards,
Bill

1 vote
Answer accepted
Hauke Bruno Wollentin
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 19, 2024

I'm not aware of some kind of a switch statement in Automation, but you could solve this with the IF/ELSE condition which also allows else ifs; inside each if you are able to define smart value conditions.

After setting the smart value variable it may be needed to re-fetch the issue data (there is an action for that available) but I'm not 100% sure about this one :) 

Yuliyan Serbezki August 20, 2024

Re-fetch the issue data? Maybe that's what I'm missing, since I'm wondering why after all this assignment the variable stays empty. Do you know how that's done?

Hauke Bruno Wollentin
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 20, 2024

It is just an action like the others :) 

Screenshot (18).png

Yuliyan Serbezki August 20, 2024

Thanks, but doesn't seem to be doing the trick. My env variable stays empty:

"env": ""

 

Hauke Bruno Wollentin
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 20, 2024

I played a bit around and it seems like the variable need to be "defined" front-up too to be accessible after running the if/else blocks.

I came up with something like this, which works for me:

Screenshot (19).png

Like # people like this
Yuliyan Serbezki August 20, 2024

Yes, that looks like it should work and is the structure I'm going for, but for some strange reason env is still empty. Even if the if else assignments don't work you would think that at least the initial value would be picked up.

The only difference I can see is maybe in your example you just pass {{env}}? And in my case I'm using that in a json so the line is "env": "{{env}}", and maybe it's possible that the substitution doesn't happen within quotes? 

Hauke Bruno Wollentin
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 20, 2024

I tried this also, seems to work.

But I'm trying this with commenting on issues here, maybe the substitution in the WebRequest action is different :( 

Screenshot (21).pngScreenshot (20).png

Yuliyan Serbezki August 20, 2024

It worked! It seems like the validation of the web request field doesn't properly process the smart variable, but in reality the value is assigned correctly. Thank you!

Like # people like this
1 vote
Leo Prakash_CodeForMe_
Contributor
August 20, 2024

Hi @Yuliyan Serbezki

If I'm not wrong you will try to assign env value based on the status instead of fetching it from issue.

if so you can build rule something like below

image.pngimage.png

 

After all conditions configured in if-else loop.

you can use the smart variable "{{env}}" that should reflect the value assigned based on condition

 

Regards,

Leo

Yuliyan Serbezki August 20, 2024

Yes, that looks good and I believe I'm doing more or less the same thing. Only difference is in the last step I use {{env}} in a json body so the line is "env": "{{env}}", and I'm wondering if because of the quotes it doesn't get evaluated?

Leo Prakash_CodeForMe_
Contributor
August 20, 2024

I don't think so the quotes are issue here. I would suggest you to use Log action component at the end and check your rule's audit log see you get expected value in env then pass it to post call you are running

1 vote
Lisa Forstberg
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 19, 2024

Hi @Yuliyan Serbezki

Welcome to the community! 

Since I'm not a developer from the start I think I would have approached this a bit simple. I would have tested to create a single select custom field called Env, with the values dev, int, stg, prodeu, produs

(Maybe this data might be interesting for Jira users to see? If not you can hide it from the view screen if its just for automations sake.)

Then in the automation:

  1. choose trigger on issue transition
  2. add issue field condition on project and statuses mentioned
  3. add branches
    1. IF statements per status f ex "Trigger Dev Deployment"
    2. edit issue field - to change the custom field  Env to what you need to thr
  4. Action webrequest include the value of Env with a smart value {{issue.Env}} in your web request body? Alternatively if you're not allowed to include custom field values, maybe action to store smart value based on {{issue.ENV}} and include the smart value in the body.

something like this..and of course repeat the branching

Screenshot 2024-08-20 at 08.46.43.png

I am however suspecting that there might me more elegant solutions to this coming from the other community experts. 

 

best regards

Lisa

Yuliyan Serbezki August 20, 2024

Hi Lisa, I've tried applying your solution and it didn't work - please correct me if you see something I've missed. When my issue transitions into one of said statuses I create the smart variable env = "initialValue" just to see if that will be used later. 

image.png

I then go on a branch for that value and start a series of if and then assign statements:
image.png

And then in the end I fire the web request. But when testing the web request "{{env}}" gets evaluated to "" which really puzzles me. I would think that even if all these if statement assignments do nothing, I would at least get that initial value that I assigned outside of the branch.

0 votes
SilkeS
Community Manager
Community Managers are Atlassian Team members who specifically run and moderate Atlassian communities. Feel free to say hello!
August 20, 2025

This topic has been locked because the thread has become a bit dated. If you’d like to keep the conversation going or have additional questions, we encourage you to start a new topic. You can read more about necro posting (“raising threads from the dead”) in our  Community Guidelines .

Thanks!

0 votes
vpass
Contributor
August 20, 2025

Hello,

I can confirm that initializing the variable component, or rather its properties, is still necessary in 2025 (even on the data center). This is so that the variables can then be used in the conditions and after the conditions. You can easily check this using the logs component. I always use an initializer at the beginning of the ARU (it doesn't need to have the same name as your variables used in the conditions; here, we simply load the properties of the component upstream of the ARU so that it can work throughout the ARU):

2025-08-20_16h04_45.png

Then you use a “for each” on a smartvalue defined to a single value, which is a strange choice. This is not a ticket field here, but rather a smartvalue created in the ARU. I advise you to approach things algorithmically in order to take a step back from the composition of the ARU and clarify your problem.

If it hasn't already been resolved, I wish you good luck ! 😉

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events