Forums

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

Jira Automation: Iterate over labels and use lookup table to map label name to an email address

Jonathan Scott
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 6, 2024

I'm trying to use Jira global automation rules to loop over the labels on a specific task when it is created/updated. If the label name exists in a lookup table (departmentEmails), then append/contact the value to another variable called "toEmails". If the label does not exist in the lookup table, but it contains an "@" symbol, also prepend/contact the label name to "toEmails".

 

I can not for the life of me get the lookup table to use departmentEmails.get(.) on the iteration of the labels. I've tried several ways, like this (using the THEN set variable command):

 

{{#issue.labels}}{{#if(departmentEmails.get(.))}}{{departmentEmails.get(.)}}; {{/}}{{/issue.labels}} 

 

but that yields an error about the ".", which is the only way I know to access the current iteration in the nested loop.

 

I even tried not using the lookup tables, but I also get an error with this:

{{toEmails}}{{#issue.labels}}{{#if(equals(., "Marketing"))}}marketing@my-company.com; {{/}}{{/issue.labels}}

 

Can anyone come up with a better way to do this? I would use the BRANCH action on a smart value but I need to also do some if/then/else logic, and that can't be done within a branch. Thank you for your help.

1 answer

0 votes
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.
August 6, 2024

Hi @Jonathan Scott -- Welcome to the Atlassian Community!

One of the limitations of automation rules is: once inside of an iterator, no data from outside is visible / available.  That is:

{{#issue.labels}} ...inside the iterator, can only see labels, and lower... {{/}}

And so your lookup table is not visible.

 

A workaround for this scenario is not to use the lookup table to perform the matching directly, but instead search the table using a regular expression built from the labels with the match() function.  This would produce a list of values to append to toEmails.

 

First, we build something to search: a delimited string built from the table, using the entries feature of lookup tables with a list iterator.  Let's store that in a variable named varDepartmentData.

{{departmentEmails.entries}}{{key}}~~{{value}}{{^last}};{{/}}{{/}}

That will produce something like this:

DepartmentA~~departmentAemailAddress;DepartmentB~~departmentBemailAddress

 

To search that text, we build a regular expression from the labels.  Let's name that variable varSearchExpression.

({{#issue.labels}}{{.}}~~.*{{^last}}|{{/}}{{/}})

If the labels where "DepartmentC, DepartmentA", that will produce something like this:

(DepartmentC~~.*|DepartmentA~~.*)

 

Putting those together, we can search and extract the result with this:

{{varDepartmentData.split(";").match(varSearchExpression).substringAfter("~~")}}

Then add other list / text functions as needed to add to your other variable.

 

Kind regards,
Bill

Jonathan Scott
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 7, 2024

Thank you so much Bill, that worked perfectly!

Like Bill Sheboy likes this
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.
August 8, 2024

Awesome; I am glad to learn that helped.

Please consider marking this question as answered to help others in the community with similar needs find solutions faster.  Thanks!

Suggest an answer

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

Atlassian Community Events