How to remind all approvers (by Slack) that have pending approval issues via automation rule

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

    screencapture-elegancegroup-demo-atlassian-net-jira-settings-automation-2023-06-15-15_19_20.png 

Here is a breakdown of each step in the automation rule mentioned above:

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

OR "Approvals[Approvals]" = pendingBy("608ac7795426330072fca171"))

{{lookupIssues}}: The list of issues that have pending approval:
Step 1.png

 

2

Create a variable to store all Approvers by using this smart value:
Step 2.png

{{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.replace("[", "").replace("]", "").replace(" ", "")}}

Step 3.png

{{listApproverEmails}}: the list of Approvers without array:

phong@abc.com,baoduy@abc.com,baoduy@abc.com,phong@abc.com

The purpose of each function:

  • .replace("[", ""): To remove the [ character.

  • .replace("]", ""): To remove the ] character.

  • .replace(" ", ""): To remove the space character.

 

4

Loop through the Approvers with values that have been distinct:
{{listApproverEmails.split(",").distinct}}

Step 4.png

  • {{listApproverEmails}}: the list of Approvers with distinct values:
    phong@abc.com,
    baoduy@abc.com

  • {{approverEmail}}: The variable to store the loop item.

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:
"Approvals[Approvals]" = pendingBy("{{approverEmail}}") AND project = ITSM

Step 5.png

{{lookupIssues}}: The list pending approval issues of each Approver.

 

6

Condition logic to check if the previous lookup actions is NOT empty:
Step 6.png

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:

{
	"text": "Hi there, there are {{lookupIssues.size}} pending request(s) that require your approval:
{{#lookupIssues}} \n * Click here (<https://YOUR-SITE.atlassian.net/servicedesk/customer/portal/6/{{key}}|{{key}}: {{summary}}>)
to approve this request for {{reporter.displayName}} \n {{/}}", "channel": "@{{approverEmail.split("@").get(0)}}" }

More details to set up the Slack incoming webhooks: https://api.slack.com/legacy/custom-integrations/messaging/webhooks
and formatting text: https://api.slack.com/reference/surfaces/formatting

Each Approver will receive Slack messages by Slackbot about their pending approval issues:
Slack message.png

 

 

 

2 comments

Nguyễn Thành Long September 4, 2023

Hi, nice work! I can see that a lot of thoughts went to this.
I'm trying to follow the guide (to send email instead of slack). However, my automation keeps having the issue:
Custom Smart Value JQL Search: "("Approvals[Approvals]" = pendingBy("") AND project = LT1) AND (project in (10266))" - There is no user ""
I suppose something went wrong in variable. Please let me know how this can be fixed. Much appreciated! 

@Nguyễn Thành Long hey bro, did you try to log/print the {{approverEmail}} to see its value inside the loop?

刘柏榕 Baron Liu _ENG - IT - CN_ September 21, 2023

@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.

刘柏榕 Baron Liu _ENG - IT - CN_ September 21, 2023

Yes, I used the distinct function.

Xnip2023-09-22_09-53-01.jpg

 

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)".

Xnip2023-09-22_10-01-42.jpg

 

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. 🤔️

Xnip2023-09-22_10-34-36.jpg

 

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?

刘柏榕 Baron Liu _ENG - IT - CN_ September 22, 2023

Hi, @Phong Nguyen - Atlassian Solutions Engineer 

Yes, My scheduled trigger includes a JQL which I deleted and now works fine.

Thanks very much! 🎉

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events