Compare Automation smart value to list of options with a Regular Expression
Platform Notice: Cloud and Data Center - This article applies equally to both cloud and data center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
If we want an Automation to be able to compare based on the Labels field or other multi-select custom fields, we need to use a Regular Expression (also called RegEx) comparison.
For example, let's imagine we wish to case-insensitively match work items with a label that starts with either "assist-" or "help-".
Solution
Build a Regular Expression in the automation rule
In our automation rule, we use a contains regular expression condition in the "Advanced compare condition."
When we use the {{issue.labels}}
Smart value, all of the labels on a work item will be returned, separated by commas. For a work item with three labels:
help-desktop
assist-email
customer-service
{{issue.labels}}
will return:
help-desktop, assist-email, customer-service
So, our Advanced compare condition must account for the label at the start of the string, or right after a comma and a space. In RegEx, we can use the pipe character "|" as the "OR" operator.
Our regex should start with: (^|, )
Then we have the strings you'd like the label to begin with: "assist-" or "help-". Our RegEx should then be followed by "(assist-|help-)
".
So, our complete RegEx in this case should be:
(^|, )(assist-|help-)
We compare this RegEx that with "{{issue.labels.toLowerCase()}}
" to make sure that letter capitalization won't get in the way.
The complete Advanced compare Condition block would look like this:
First value:
{{issue.labels.toLowerCase()}}
Condition: contains regular expression
Regular expression:
(^|, )(assist-|help-)
Was this helpful?