How can I use Advanced Branching in Automation for unique results?

Brock Jolet
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 12, 2022

I created an automation a while back that sends emails daily to the assignee of any issue that is overdue. This resulted in numerous individual emails for some users and I was asked to instead send out bulk emails.

Here is my basic workflow:

  • When the rule is triggered, run a JQL query to find all issues that are in an active status.
  • I then pass the results through an IF statement checking for issues that have assignees and are currently overdue.
  • Within the IF, I added an Advanced Branch that does an action for each assignee from the issues that passed. (This is where I need help.)
  • I use the variable {{currentAssignee}} from the Advanced Branch to run a JQL lookup that returns only the issues assigned to that user.
  • Finally, I trigger an email with those results in bulk.

It almost works. The problem I run into is Automation doesn't filter the assignees for unique users. So if a user has five overdue issues, they will receive five identical emails with all of the issues listed.

I've searched and come up empty-handed trying to find a way to filter the list of assignees for unique ids. Any help is appreciated.

Screenshot below:

2022-01-12_11h53_08.png

2 answers

1 accepted

3 votes
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 12, 2022

Hi @Brock Jolet 

There appears to be a newer (?) feature for lists which allows pulling distinct values: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#list.distinct

Given what is described and your use case, I expect you could use a Lookup Issues action to find issues meeting the criteria: has an assignee and is overdue.  Then use this to populate a created variable: {{lookupIssues.assignee.distinct}}

And then split that created variable back into a list to drive the advanced branching, with one loop for each assign.  The reason I suggest the created variable is so you can use lookup issues within the branch to create one email per assignee.

Kind regards,
Bill

Brock Jolet
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 13, 2022

Thanks, @Bill Sheboy .

This put me on the right path to accomplish my goal.

I originally was going to do more actions in the same rule, but opted for multiple rules. So I was able to remove the IF statement and removed my JQL search from the Cron.

I didn't need to store a custom variable, but I did use {{lookupIssues.assignee.distinct}} to feed the Advanced Branching. That was key.

I wonder if this is what @John Funk was hinting at in his post.

Here's a screenshot of the final rule:

2022-01-13_10h37_41.png

Like # people like this
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 13, 2022

Yes, it was - sorry, just now able to get back to this. 

Like # people like this
Peter
Contributor
February 19, 2022

Does anyone know if the list.distinct capability can be used in Advanced Branching in the Cloud version of Automation?  I have a very similar use case, but when I try to do as described here, with a copy-pasted {{lookupIssues.assignee.distinct}}, I get the following error:

The provided smart value was unable to be resolved to an object.
When I just use {{assignee}} for the smart value, I get no such error - the automation runs, although it repeats for each issue rather than each assignee.
I've tried searching for cloud availability to use "distinct" in Advanced Branching, but can't find anything that indicates either way.
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.
February 22, 2022

Hi @Peter 

Assignee is an object in the smart values (with several attributes), so distinct may not work until you get to the level of a single attribute, like the accountId.  Perhaps try {{lookupIssues.assignee.accountId.distinct}}

and then split the results so they can be used in the advanced branch.

Kind regards,
Bill

Peter
Contributor
February 25, 2022

Thank you, @Bill Sheboy - I gave that a try but came away with the same error. (Also tried {{lookupIssues.assignee.displayName.distinct}} with the same result.)  I'm at a loss for how to parse the results into distinct assignees only

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.
February 25, 2022

Peter, I tried your original expression with Jira Cloud and it worked for me.  The results in the advanced branch were to return the accountId automagically...as that appears to be the default attribute when used this way.

Please confirm your smart value capitalization as smart values are case-sensitive.

Note that my lookup issues JQL returned issues with and without assignees, and the use of distinct only returned assigned issues.

And of note: did you use a Variable name of "assignee" in the branch?  If so, that would explain the error as that is a reserved name for the smart value.  A tip is to always prefix your created variables and advanced branch variables with "var..." as shown below to make it unique.

Capture.PNG

Peter
Contributor
February 28, 2022

Thank you, @Bill Sheboy - I think I found the root of my problem.  In case this helps anyone else in the future...

@Brock Joletsaid "I originally was going to do more actions in the same rule, but opted for multiple rules. So I was able to remove the IF statement and removed my JQL search from the Cron."

I interpreted the way this was written to mean it was purely an optional decision (ie, "i opted to"), and that it could work even if you don't do that - but it can't. You must remove the JQL condition from the scheduled trigger, and the only way to do that is to remove any JQL conditions from the rule. So you HAVE to break this up into multiple rules in order for it to function as described here, so that you have no JQL in the scheduled trigger and no JQL conditions.

If you don't/can't remove the JQL from the scheduled trigger, that's when you wind up getting an email per issue rather than an email per assignee.

Deleted user May 25, 2022

Hello @Brock Jolet@Bill Sheboy,

This post is exactly what I was looking for for an answer, so thanks for that.

 

I only have 1 issue - My email is being sent out to me, and only me. It recognizes that there are different users, as per the log:image.png but when I hit "run rule" to test it, it's only sending me the mail (examples of 2 emails from the same automation run):

image.pngimage.png

I've tried setting the email recipient to assignee, and the smart value created, but I just get the same result each time. Any help would be much appreciated :)

My rule for comparison:

 

image.pngimage.pngimage.png

 

Thanks!

Jack 

Like Petr AST likes this
Brock Jolet
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 25, 2022

Hello Jack,

I think Automation is not able to pull the email address of the {{currentAssignee}}. It needs to be explicit.

See my example of a working rule below:

Screenshot 2022-05-25 150202.png

Like # people like this
Deleted user May 26, 2022

Fixed!

 

Fantastic, thanks very much!

Like # people like this
Shannon
Contributor
August 16, 2022

@[deleted] & @Brock Jolet

I have been staring at your conversation for the past 2 weeks. I've finally been able to make it work and get automated emails direct to my team. 

I *heart* you guys soooo much. 

@John Funk , I didn't need to bother you again!!!! 

Cheers all, I've become  drunk on happiness 

Like # people like this
0 votes
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 12, 2022

Hi Brock,

Take a look at this previous post. I would use the lookupIssues smart value function to do that. 

https://community.atlassian.com/t5/Jira-Software-questions/Sending-an-email-with-a-list-of-issues-using-Automation-for-Jira/qaq-p/1192501

Brock Jolet
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 12, 2022

Hello @John Funk , 

I read through that thread and don't think it addresses my issue. I'm already producing emails with a list of issues via the Lookup Issues component. The problem is that I'm getting multiple emails with the same information instead of just one.

I'm returning a list of issues from my IF statement, pulling out the list of assignees for those, and then using the Lookup Issues component to run a new query for populating the emails.

I'd like to figure out how to take the list of assignees and strip it down to only unique IDs before passing them into the Lookup Issues component.

Please correct me if I misunderstand how you would use the Lookup Issues component.

Like John Funk likes this
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 25, 2022

Hey @Brock Jolet 

So sorry, I was out of the office around this time and missed any kind of email notification. Did you ever get this solved? 

Also, it's good practice to always create a new question in the Community instead of adding to an already existing thread. That way more people will see it.  :-)

In fact, if it's still a problem, I would suggest you create a new question. I and others should see it then. 

Like Shannon likes this
Tomas Slavkovsky
Contributor
October 13, 2022

@Brock Jolet, I had similar problem, receiving multiple emails instead of one, solved by adding smart value {{lookupIssues.assignee.distinct}}

 

Screenshot 2022-10-13 at 15.35.52.png

Like # people like this

Suggest an answer

Log in or Sign up to answer