Jira product: Jira Service Management
Version: 9.12.12
-----------------------------------------------
Hello,
I have an automation in which I want to conditionally set smart variables through if-else blocks and use the resulting variables in a POST web request hook,
When I try to have a single web hook in the very end of the automation, after the if-else blocks, nothing happens. Contrary, if I add the POST request to every if-else clause, it works as expected, however a lot of redundancy and tedious to maintain,
I want to have a single web request like the above, in the very end.
BONUS: If you have a way to shorten it by setting the smart variables, conditionally, without neither if-else blocks nor looktup tables, I would appreciate that as well :)
Hi @Frederik Strøm Friborg -- Welcome to the Atlassian Community!
Short answer: if you create your comment and transitionId variables with default values before any rule conditions, their values will likely be preserved after updates (replacements), allowing the use of a single web request action at the end of the rule.
More information...
Your question seems to be about variable scoping, and when the created variable values are preserved. The "trick" for automation rules is sometimes value updates can be preserved (i.e., shadowed) and sometimes not.
I will try to explain with an example rule:
Because the variable is created before any rule structures, it can persist and be updated using shadowing. But only in some cases...
After the variable is created, of course its value is correct.
After the if / else block, the value can be replaced.
After a branch on one-and-only-one-issue, the value can be replaced.
After a branch which could be on more-than-one-issue, the value is not replaced.
In the last case, each pass / loop through the branch is a separate process, and so each variable created inside is new and thrown away when done. After that second branch, we expect the variable to retain the last value before the branch started.
Kind regards,
Bill
Wonderful!
Thank you kindly Bill, exactly the answer I was looking for :)
Best,
Fred
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.
Your automation is not using 2 IF/Else blocks.
The first if is a comparison, not an IF/ELSE.
The second is an IF/ELSE, if you use and IF/ELSE an action is mandatory, you can't use and IF/ELSE without having an action outside the IF/ELSE.
Based on your rule, you need the web request twice, there is no other option for you based on the conditions you are using.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Marc - Devoteam
Thank you very much!
Sorry, I realise the image does not capture enough context; I have multiple else-if statements underneath the if statement that do not show on the image...
Every if/else-if/else clause matches a status and sets smart variables comment and transitionId based on the matched status and adds those to the web request, as in the image,
The problem is that I have to add the web request inside every single if/else-if/else statement for it to work, instead of having it run after the IF/ELSEs, just once, like so:
if (status == 1):
comment = some comment
transitionId = some id
else if (status == 2):
comment = other comment
transitionId = other id
webRequest.execute(comment, transitionId)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you use and IF/ELSE an action is mandatory, you can't use and IF/ELSE without having an action outside the IF/ELSE
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.