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?
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:
Kind regards,
Bill
Thanks Bill! That definitely looks tidier - that's what I was hoping for when I started.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is just an action like the others :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, but doesn't seem to be doing the trick. My env variable stays empty:
"env": ""
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
something like this..and of course repeat the branching
I am however suspecting that there might me more elegant solutions to this coming from the other community experts.
best regards
Lisa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
I then go on a branch for that value and start a series of if and then assign statements:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.