Basically I'm trying to create an automation where I have an API that receives email addresses. In the "advanced branch for each" component I call the Jira API to get the accountId by the email address and update the approvers field (Multi picker user) with the JSON below in additional fields.
{ "update": { "Approvers": [{ "add": {"id":"{{webResponse.body.accountId}}"} }] } }
The problem is: Sometimes it works perfectly and other times it only adds one approver, but there are others.
I don't know if it would be a bug, but since it doesn't always work the same way, I have to find another way to do it.
I'm following the articles below, with the growth of for each e-mail address. What could be causing the problem. Any ideas? Thanks.
https://confluence.atlassian.com/jirakb/retrieve-data-with-jira-rest-api-in-automation-to-update-issue-fields-1319243229.html
https://confluence.atlassian.com/jirakb/dynamic-update-the-approval-in-jira-work-management-projects-1402408714.html
For those interested. In my case, I had a "simple" idea that managed to do what I was looking for.
Inside the foreach, after updating the approvers field, I call "Re-fetch Issue", then an if validating the field does not contain that Id. If it does not, I update it again.
The process is executed asyn, it will trigger a new thread for server and force the field to be updated. Its a "double-check" the value is correct.
Hi @Tiago Ervatti
Welcome to the community.
Whenever you ask for help with an Automation Rule it will help us to help you if you provide:
1. what type of project is this (e.g., company-managed, team-managed, etc.),
2. images that show your complete rule.
3. images showing the details of any relevant actions/conditions/branches.
4. images showing the Audit Log details for the rule execution.
5. Explain where the issue is.
These questions are not for not willing to help, but to have community members understand on how your automation works.
Hi @Tiago Ervatti -- Welcome to the Atlassian Community!
Are you describing a single web response could contain multiple accountId values, or something else?
If the web response could contain multiple values, you could iterate over them in the dynamically created JSON expression to add them.
If instead there are multiple calls to the REST API, each one returning one accountId to add as an approver, the rule could use advanced branching to add them one by one.
Kind regards,Bill
It's the second option @Bill Sheboy .
I have an array of email addresses split with "," in the foreach. I call the Jira API with one email at a time (https://xxx.net/rest/api/3/user/search?query={{Email.urlEncode}}) and it returns an accountId {{webResponse.body.accountId}}.
In the same foreach, I update the "approvers" field with the Json bellow to add all the accountId returned from Jira according to the email address.
Sometimes, all of them are added, other times only one.
Thanks for help.
Thanks for that information, and there are multiple causes for that symptom. Seeing the complete rule and audit log details for the rule executions (as @Marc -Devoteam- requested) may help to confirm these.
For example...
Perhaps the REST API call does not return a value for one-or-more of the email addresses, leading to an attempt to add an empty value. That one seems unlikely...
The most likely cause is rule branches which could be on more-than-one-thing run in parallel and asynchronously. And so I wonder if the updates are failing due to collisions. Or, it is working but the results are checked too soon while the updates are in progress.
Let's assume it is a branching problem from parallel processing. One possible solution is using a different endpoint, a dynamic regular expression, and add all the Approves with one edit:
Hi,
I created a simple and isolated automation. A variable with many "Accountid" separated by "," foreach split (","), and update the approvers field with a single Id at a time and the problem persists.
Attached the automation. For test, change the summary field of any issue and update the accountIds variable with valid and active Ids separated by "," in the automation.
All Ids always appear in the log, but the field is updated randomly. Sometimes all Ids, sometimes just one, just another etc.
I believe it has to do with asynchronous processes as you mentioned. It seems to be a problem in the component.
I'm thinking... set the variable with Ids inside the foeach (simulating the Jira API call) and outside the foreach, update the field all Ids at once.
Could you help me with this? Thanks.
https://drive.google.com/file/d/1JurG-c0dsshf1zaT0iYDIEBz3I6HCQHX/view?usp=drive_link
It looks like you're new here. Sign in or register to get started.