Forums

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

How to branch in automation and return results from each loop back to rule

Michelle Sullivan May 22, 2025

So am trying to create an automation based on a comma separated list of data that gets passed out to an external site/url then it collects the returns for the requests and put it in a comment.

 

Currently have this working like a treat except that each loop on the data creates a comment on a single result request.. so if I add 40 pieces of data I get 40 comments. 

This works but is quite unreadable and wanted to create a table of results and pass that into a single comment in the issue.. is this possible?

For reference this is the data that currently goes in each comment:

 

Target: {{userProvidedListItem}}

🧾 Response

- **HTTP Status:** `{{webResponse.status}}`
- **Message:** `{{webResponse.body.message}}`
- **Details:**
- `statusCode`: `{{webResponse.body.details.statusCode}}`
- `body`: `{{webResponse.body.details.body}}`

 

Ideally I'll process these a little differently before adding them to the comment.. for example if {{webResponse.status}} is 200 I don't need to record it - but if its 4xx or 5xx I should record it.  So a resulting comment might be displayed as a Table such as:

 

Target                   | Message                      | code                                    | body
=====================================================================================================================================
{{userProvidedListItem}} | {{webResponse.body.message}} | {{webResponse.body.details.statusCode}} | {{webResponse.body.details.body}}
{{userProvidedListItem}} | {{webResponse.body.message}} | {{webResponse.body.details.statusCode}} | {{webResponse.body.details.body}}
{{userProvidedListItem}} | {{webResponse.body.message}} | {{webResponse.body.details.statusCode}} | {{webResponse.body.details.body}}
{{userProvidedListItem}} | {{webResponse.body.message}} | {{webResponse.body.details.statusCode}} | {{webResponse.body.details.body}}
{{userProvidedListItem}} | {{webResponse.body.message}} | {{webResponse.body.details.statusCode}} | {{webResponse.body.details.body}}

 

Where each line (data and result) corresponds to each loop iteration.

 

Thanks,

 

Michelle 

1 answer

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.
May 23, 2025

Hi @Michelle Sullivan -- Welcome to the Atlassian Community!

For a question like this, context is important for the community to help.  Please post the following:

  • what version of Jira are you using: Cloud, Server, or Data Center
  • for Cloud, what type of project is this: company-managed, team-managed, JPD, etc.
  • an image of your complete automation rule in a single image for continuity
  • images of any relevant actions / conditions / branches
  • an image of the audit log details showing the rule execution
  • explain what is not working as expected and why you believe that to be the case

Until we see those...

 

Automation rule branch which could be on more-than-one-thing execute in parallel and asynchronously, with no guarantee of when the branch will finish up until the last step of the rule.  (There is an in-progress suggestion to make this configurable, and we have no idea what Atlassian will actually implement for it.)

For your apparent scenario, the steps after the branch will start running before the branch completes, and so one comment would not be possible if each pass through the loop is calling out to a REST API endpoint.

Possible workarounds depend upon the number of items and your risk-tolerance for complex rules:

  • Build this completely outside of Jira, greatly simplifying the rule and reducing the risk of errors
  • Build an external endpoint which can loop over and accumulate the results, and call that one from the rule, finally adding the comment from the web response
  • Try a recursive rule approach (which can be risky, error-prone, and brittle)
    • Create one rule which starts the process, can calls another rule using the Send Web Request action
    • The second rule uses an Incoming Webhook trigger, and recursively processes the items, calling itself again and chaining results.  When there is nothing else to process, add the accumulated results in the comment.

 

Kind regards,
Bill

Michelle Sullivan May 23, 2025

Yeah thought that might be the result...  Just refactored to try something different..  editing a known comment with the last result...

That also doesn't work most of the time .. seems that the branch iteration can edit the comment at the same time as another branch iteration wiping out it's result.. (ie no locking on a comment)

This is the rule:

Michelle Sullivan May 23, 2025

 

unknown.pngimage.png

Michelle Sullivan May 23, 2025

The result is:

Unknown.png


I do however get 5 emails to the ticket and the API call has the 4 valid requests... so the branch is working..  just the results is "potluck" on which one is recorded.

As for the other parts.. it does mention/is tagged.. Jira Cloud/Premium

and finally:

Unknown.png

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.
May 23, 2025

Thanks for that information, and...

Based on the rule shown I would expect the comment edits to collide frequently and "walk over" the prior results, and with no predictable order of processing due to the parallelism.  Thus the final comment may not be correct.

Like • Michelle Sullivan likes this
Michelle Sullivan May 23, 2025

Funny thing is, that's ok .. (comments being in any order) the issue is the dropping/walking over of results.I'm about getting the job done and recording that, rather than requiring a specific order of execution.

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.
May 24, 2025

Please see my earlier suggestions for workarounds; a single rule with a branch will produce unpredictable results in the comment edits.

 

Let's look at an similar example, where the branch values are A, B, C, and D, and we are just looping to add to the last comment's body:

  • trigger: manual (and assuming the work item as at least one comment)
  • action: create variable
    • variable name: varList
    • smart value: A, B, C, D
  • advanced branch:
    • variable name: varItem
    • smart value: {{varList.split(", ")}}
      • action: edit comment, setting the value to...
        • setting the value to: 
          • {{currentComment}} -- {{varItem}}

 

As noted earlier, the order is unpredictable.  But so is the content of that comment...

  • let's assume they process in order, and in parallel: A, B, C, D
  • after the first one runs, the comment might contain:
    • old comment text -- A
  • but because they are running in parallel, that could be walked over, causing the comment to now only contain; this is assuming that "B" is slightly later in time
    • old comment text -- B
  • and so on, where we truly have no idea what will end up in that comment:
    • A
    • A, B, C, D
    • D, C, B, A
    • D
    • ...

I hypothesize the {{currentComment}} smart value leads to an additional REST API call in the automation engine, but who knows what that contains as the loop progresses.

Like • Michelle Sullivan likes this
Michelle Sullivan May 25, 2025

What we need is like threading in C ... a 'pthread_join()' like function where the caller of the branch can pause waiting results of the entire branch.  That way we could collate the parallelized call results and process them after all have been done. (because in my case I just need the results, I don't care about order.. and if order was something that mattered it would be trivial to fix that in what's available in automation now.) 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events