Forums

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

Jira Service Management: How to wait until end of automation to call web request?

Frederik Strøm Friborg January 9, 2025

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,

choppe.png

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 :)

2 answers

1 accepted

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

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:

  • trigger: manual
  • action: create variable, named varData, with a value of "#1 at the start"
  • action: log to echo "value after created: {{varData}}"  RESULT: value is unchanged.
  • if / else block
    • some condition leading to true...
    • action: create variable, named varData, with a value of "#2 inside if / else block"
    • action: log to echo "value inside condition: {{varData}}"
  • action: log to echo "value after condition: {{varData}}"  RESULT: value is changed.
  • branch: to current issue
    • action: create variable, named varData, with a value of "#3 inside branch current issue"
    • action: log to echo "value inside first branch: {{varData}}"
  • action: log to echo "value after first branch: {{varData}}"  RESULT: value is changed.
  • branch: on JQL to several different issues
    • action: create variable, named varData, with a value of "#4 inside branch on JQL"
    • action: log to echo "value inside second branch: {{varData}}"
  • action: log to echo "value after second branch: {{varData}}"  RESULT: value is NOT changed.

 

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

Frederik Strøm Friborg January 16, 2025

Wonderful!

Thank you kindly Bill, exactly the answer I was looking for :)

Best,
Fred

Like Bill Sheboy likes this
0 votes
Marc - Devoteam
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 9, 2025

Hi @Frederik Strøm Friborg 

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.

Frederik Strøm Friborg January 10, 2025

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) 
Marc - Devoteam
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 10, 2025

Hi @Frederik Strøm Friborg 

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events