Goals
The reminders should run in schedules (daily or custom schedules) and send the list of all pending approval issues to each Approver via Slack.
Only use Jira automation natively (not involved with Zapier) to loop through all the relevant Approvers and send reminders to them.
The automation rule with all steps (Please find the clarifications mentioned below):
Step | Details | Output value | Note |
---|---|---|---|
1 | Lookup issues by this JQL: project = ITSM AND "Approvals[Approvals]" = pending() To restrict testing to certain users, we can append a JQL query with their specific user IDs: AND ("Approvals[Approvals]" = pendingBy("61dfe44b7c6f980070c2d25a") | {{lookupIssues}}: The list of issues that have pending approval: |
|
2 | Create a variable to store all Approvers by using this smart value: {{lookupIssues.Approvers.emailAddress.distinct}} | {{listApproverEmails}}: the list of Approvers: [phong@abc.com], [baoduy@abc.com], [baoduy@abc.com, phong@abc.com] (It’s a list of multiple arrays). | The distinct function only remove duplicate array, not items in the array. |
3 | Create the same variable and remove the [, ] and space characters: | {{listApproverEmails}}: the list of Approvers without array: phong@abc.com,baoduy@abc.com,baoduy@abc.com,phong@abc.com
|
|
4 | Loop through the Approvers with values that have been distinct: |
| The .split(",") function did the trick to convert a string with , characters to a list to loop. |
5 | Lookup issues to get the pending approval issues of each Approver in the loop: | {{lookupIssues}}: The list pending approval issues of each Approver. |
|
6 | Condition logic to check if the previous lookup actions is NOT empty: | Continue the rule if it passes the condition. |
|
7 | Send Slack messages to the target username (NOT channel) by sending the webhook to the configured Slack Incoming WebHooks with a customized channel field from the JSON body:
More details to set up the Slack incoming webhooks: https://api.slack.com/legacy/custom-integrations/messaging/webhooks | Each Approver will receive Slack messages by Slackbot about their pending approval issues: |
|
@Nguyễn Thành Long hey bro, did you try to log/print the {{approverEmail}} to see its value inside the loop?
@Phong Nguyen - Atlassian Solutions Engineer
Hi, I have used your rule in my project and it work.
However, we have found that approvers receive duplicate Slack messages.
For example:
My project has 2 tickets in pending approval status and each of these 2 tickets has a different approver.
Then approver A will receive 2 Slack messages with the same content. same for approver B.
Like this:
Hi there, there are 1 pending request(s) that require your approval:
* Click here (XXXX-0001: XXXX Request) to approve this request for XXX
Hi there, there are 1 pending request(s) that require your approval:
* Click here (XXXX-0001: XXXX Request) to approve this request for XXX
Following the same logic, the approver will receive X Slack messages with the same content if the project has X tickets in Pending Approval status.
Not sure if you are having the same issue?
Hey @刘柏榕 Baron Liu _ENG - IT - CN_ , did you use the distinct function in step #4?
{{listApproverEmails.split(",").distinct}}
You should use Log action in the automation to check each {{approverEmail}} item in the loop to see if it's duplicated.
Sometimes, it might be caused by you creating 2 of the same automation rules but you forgot to disable one of them.
Yes, I used the distinct function.
I copied your steps almost exactly in my project, the only difference is that “approver" field I replaced it with our custom field “Approver (Single user)".
I tried searching using JQL and confirmed that there was only one ticket that required my personal approval.
I also tried printing the text of the Slack message and {{approverEmail}} to the audit log using the log action, which resulted in 4 approver email addresses and 4 messages, one of which was for me. So this is as expected.
But as you can see in the screenshot, my slack received 4 messages.
So that makes me wonder. 🤔️
Hey @刘柏榕 Baron Liu _ENG - IT - CN_ Can you check if your scheduled trigger includes any JQL? For this approach to work as expected, the scheduled trigger should NOT use any JQL.
I think your scheduled trigger also includes the same JQL of the lookupIssues, so it multiplies the loops.
If you still can't find the root cause, can you export your rule as the JSON file, and I can import it to my test side and check it?
Hi, @Phong Nguyen - Atlassian Solutions Engineer
Yes, My scheduled trigger includes a JQL which I deleted and now works fine.
Thanks very much! 🎉