Automation to add labels based on text present in summary or description

Daniel Helmstedt January 23, 2022

Looking for advice on streamlining an automation.

I'd like to have a list of values (applications/components/common pain points). For each issue created, i'd like to check the Summary and Description against that list, and for each match (eg summary OR description contains WiFi and Printing, to then add a label for each match. So this example would add 2 labels - 'WiFi' and 'Printing'.

 

I'm trying to condense this from a whole bunch of If/Else blocks... would appreciate any thoughts

3 answers

1 accepted

1 vote
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 24, 2022

Hi @Daniel Helmstedt -- Welcome to the Atlassian Community!

One way to do this would be to create your list of check values in a created variable, separated by commas.  And then use advanced branching to iterate over them.  For example

  • trigger: issue created:
  • action: create variable with your list
  • advanced branch: splitting the created variable into a list
    • condition: check if the value is found (from the branch variable)
    • action: add the label
    • action: re-fetch the trigger issue

Another way to do this is with a regular expression, copying the source field (e.g. Summary)  to a created variable, and then replacing anything not in your search list of terms with an empty string.  Then parse the results into a smart value list and add all of the labels at one time using an advanced JSON edit expression.

Kind regards,
Bill

Daniel Helmstedt January 24, 2022

Thanks Bill! That's a much simpler flow than I was working on!

How would you go about checking the smart value against both Summary and Description - can that be done in one step? 

Cheers!

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 24, 2022

Hi, Daniel.

If you mean the second thing I suggested, I meant removing the non-matching expressions (i.e. to your tests) with a RegEx and then using the remainder to create the list for the labels.  This is certainly going to take a bit of experimentation to get correct; the specifics of your search strings may not make this approach viable.

The first approach I noted should be easy to try and get working...giving you time to experiment with the second approach.  That would only require use of advanced compare conditions with "contains" or use of the text searching functions.

Regarding your ask about checking Summary and Description in one step, you could concatenate them first, and then test for the string match.

Matthew Day February 16, 2022

Hi @[deleted] 
I checked the link for text searching functions, as I wanted to do something similar, but I couldn't find anything for 'contains' other than contains all letter or all numbers, not matching keywords. 
How does the syntax to match keywords work? 

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 16, 2022

Hi, Matthew.  Please try using match() with a regular expression, and then check that the result is not empty to then add the relevant labels.

Ryan Van Zyl June 30, 2022

Hi @Bill Sheboy 

I should probably have created a new ticket but this is exactly what I was searching for. I am trying to do the same thing but I just started yesterday. 

would it be possible to further explain this:

 

  • trigger: issue created:
  • action: create variable with your list
  • advanced branch: splitting the created variable into a list
    • condition: check if the value is found (from the branch variable)
    • action: add the label
    • action: re-fetch the trigger issue

 

How do I create a list, I’ve read through the smart values list but I am unsure of how to create a list 

 

And once I do the check if the value is found, how do I input that as a label. I can’t see any way to pass the information from the list into the labels based on the results. If I could find out in general how this is done it would be great, because being able to pass the information from the branch to the action would be great 

 

your help would be highly appreciated.

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.
June 30, 2022

Hi @Ryan Van Zyl -- Welcome to the Atlassian Community!

First thing: lists

To make a list, you supply the values with some delimiter, such as comma.  That will still be a text string.  Then when you need it as an actual list, you can use the split() function for use as needed.  For example...

  • Create a variable
    • Name: mySearchValues
    • Value: apple,orange,squirrel,diamond
  • Later when you want to iterate over the values as a list in the advanced branch, split it
    • smart value: {{mySearchValues.split(",")}}
    • variable name: {{myValue}}

Next thing: adding your found value as a label

This is the easy part, using Edit Issue, select Labels, the ... option to Add/Remove labels, and then just enter your smart value of {{myLabel}} from the branch.  The "trick" is to type in your smart value in the field and it will appear below the field; when it does, select it to use it.

Kind regards,
Bill

Ryan Van Zyl June 30, 2022

Thank you so much, I understand now how I am supposed to use smart values. I work for a big company (this is not my company email) and they want me to automate a lot so this really has saved me a lot of time.

Thank you so much again!

Like Bill Sheboy likes this
Melle van Keulen November 1, 2022

@Bill Sheboy @Ryan Van Zyl Can you elaborate on the first method explained (see below). I'm still not getting how to realise this.

"That would only require use of advanced compare conditions with "contains" or use of the text searching functions.

Regarding your ask about checking Summary and Description in one step, you could concatenate them first, and then test for the string match."

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.
November 1, 2022

Hi @Melle van Keulen 

The idea would be to use functions, such as match(), to extract the text you want to search, and use the value to check in the second compare value.

Another approach, suggested earlier, is to build a list of value to check in a created variable, and then iterate over them with and advanced branch to check them one by one.

If you already have a rule which is not working as you expect, I suggest creating a new question, adding a link to this post, and including images of your complete rule and audit log details.  That will help more members of the community to see it and offer suggestions.  Otherwise only the people currently following this post will see your question.

Kind regards,
Bill

0 votes
Marc van Niekerk March 6, 2023

This is really helpful in solving something I am trying to implement.

 

I am hitting a really odd issue though.

In my scenario, I have a custom field that looks like item1, item2, item3

I created a variable (VAR1) that populates with {{issue.customfield_11111}}

Then created the For each Smart value branch using {{VAR1.split(", ")}} as smart value VAR2. Yes this has an extra space since the original data had one and it failed previously.

Then I populate the label field with new (VAR2) variable 

Rule runs successfully, but label only adds item2 as a label.

If I remove the refetch, the same occurs. I probably have missed something really stupid but not sure what

 

Edit: Removed the trailing space and now it only shows item3. Might be onto something

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.
March 6, 2023

Hi @Marc van Niekerk 

Since I originally responded to this question, I learned more about this use case and the parallel processing of branches on more-than-one-thing (i.e., issue, value, etc.)  Because of this one issue edit could "walk over" prior results.  Although there could be another cause for your rule.

Without seeing the specifics of your rule, I suggest a better way to do this is to gather all possible label additions and build a JSON expression, and then perform one single issue edit using the advanced edit to add the labels.

Kind regards,
Bill

Marc van Niekerk March 7, 2023

Hi @Bill Sheboy 

Yes that is exactly what I was seeing. I will have  go at trying the JSON expressions. 

 

Not used that before so a bit unsure on how I can feed it a list of labels that is not pre-defined. Assume variables would work but would still need to then split it?

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.
March 7, 2023

Here is the documentation on adding labels with JSON, and here is an example of how to do this with created variables...

Let's say you want to set the hard-coded value in a variable and then add the label with JSON.

  • action: create variable with
    • variable name: varAddLabels
    • smart value: { "add": "myNewLabel01" }
  • action: edit issue with advanced edit
{
"update": {
"labels": [
{{varAddLabels}}
]
}
}

The created variable is building a string to use in the JSON.

Now if you wanted to add multiple new labels, based on your custom field, you change the variable to iterate from your custom field instead.  This assumes your custom field is a multiple-select option list, so please adjust accordingly.

  • action: create variable with
    • variable name: varAddLabels
    • smart value: {{#issue.customfield_11111}}{ "add": "{{value}}" } {{^last}}, {{/}}{{/}}
Marc van Niekerk March 14, 2023

Had to step away form this a bit, but will try this and pick it up again when I can. 

 

Thanks for the help! will reply once tried to confirm

Like Bill Sheboy likes this
Marc van Niekerk March 28, 2023

Hi @Bill Sheboy 

 

Managed to have another look at this. your comment states that the custom field is a multi-select list, which is not the case for me. I had not spotted that so I assume that is why I get JSON errors. 

my custom field is a text field that literally would have Value1, value2, value3 as entries for example.

Using your suggestion I either keep getting invalid JSON or when I try to use a split function I get the "cannot contain space".

I tried using ".labels.asJsonStringArray" but that then failed with: (Specify the value for labels in an array of strings (labels)), which I assume suggests my variable is then not right.

 

I got the feeling I am close but just got that little gap in my kmowledge on how to manipulate the data.

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.
March 28, 2023

Would you please post images of your complete current rule, including details of any created variable actions or edits with JSON, and the details of the audit log showing the rule execution?  That may help provide context for what you are seeing.  Thanks!

Marc van Niekerk March 29, 2023

Hi @Bill Sheboy 

this is the current iteration 

 

rule_overview.png

The steps are:

create variable:

create_variable.png

for loop:

for_each_smartvalue.png

edit issue:

Edit_JSON.png

with the audit saying:

rule_audit.png

 

I am probably being really dumb to be honest

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.
March 29, 2023

No worries; writing automation rules is a lot about learning and experimentation, and we are all doing both of those things :^)

For your scenario, I would recommend using one edit to add the labels, rather than use branching, as I described earlier in this thread.

The difference is that rather than starting with a multi-select option field, you would feed this from a split of your text custom field, like this for the varAddLabels part:

{{#issue.customfield_11401.split(",")}}{ "add": "{{value}}" } {{^last}}, {{/}}{{/}}

The split turns for text field into a list, which then can be iterated over to build JSON to add labels.

Marc van Niekerk April 5, 2023

hi @Bill Sheboy 

 

I had some level of success and failure with this.

If I set my rule to create a single variable using your split then have an edit issue field with the following JSON:

{
"update": {
"labels": [
{{LabelTest}}
]
}
}

The rule succeeds, but no labels get added.

Then I reasoned to change it to :

{
"update": {
"labels": [
{"add": "{{LabelTest}}"}
]
}
}

Which resulted in (The label '{ "add": "" } , { "add": "" } ' can't contain spaces. (labels)) again.

I then reasoned that I would try:

{
"update": {
"labels": [
{"add": [{{LabelTest}}]}
]
}
}

but that gave this error: (Operation value must be a string (labels))

 

I got a feeling it is close, but it just needs that last hurdle. I tried to add a space to the split function to get split(", ") but that still resulted in space error

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.
April 5, 2023

Let's check some things to see where the problem may be...

First thing, with this technique, you would have a single issue edit using JSON and no branch in the rule.  Is that what you have currently?  If not, please post image of your latest rule.

Next, please try writing just the created variable {{LabelTest}} to the audit log using the Log action.  That will help confirm if the custom field is being converted properly into well-formed JSON.

Marc van Niekerk April 13, 2023

Hi @Bill Sheboy 

Can confirm that all branching has been removed.

The log action was helpful. the output is: 

log:
{ "add": "" } , { "add": "" }
based on the variable created with:

{{#issue.customfield_11401.split(", ")}}{ "add": "{{value}}" } {{^last}}, {{/}}{{/}}

so it would appear it is not happy with this variable. 

 

I did add extra logging to see if the customfield  did have a value which it does report:

log:
test1, test3

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.
April 13, 2023

Thanks, and that helps a lot to explain this.

Your custom field is text, and you are splitting the value with a comma-and-space.  That results in a list...and...the resulting items have no name, such as {{value}}

When iterating a list you can access the current item with {{.}} so please try this for your created variable: 

{{#issue.customfield_11401.split(", ")}}{ "add": "{{.}}" } {{^last}}, {{/}}{{/}}
Marc van Niekerk April 14, 2023

@Bill Sheboy that was the ticket! I tried list creation before but clearly did not do that correct.

Thank you so much for the help! this has been really valuable to me to learn

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.
April 14, 2023

Awesome!  I am glad to learn that helped.

Jelena Tatomir October 7, 2023

Hi @Marc van Niekerk 

Hi @Bill Sheboy 

 

Would you please share the print of Automation that works?

I would like to copy selected values of combo box to Label field, since Combo cannot show in List view.

 

Many thanks

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.
October 7, 2023

Hi @Jelena Tatomir 

First thing, I recommend creating a new question and linking back to this one rather than adding more questions to it.  Otherwise only the people following the older posts will see it to provide ideas.  Thanks!

Next, if you review this thread's content, and how to use an advanced branch to iterate values, I believe you will have everything you need to create a rule to do what you ask.

Finally, using automation rules requires learning and experimentation.  If you have started a rule and have run into challenges, please post images of your rule and the audit log in a new question, describe the problem you are trying to solve, and explain what is not working as expected.

Kind regards,
Bill

Jelena Tatomir October 8, 2023

Hi Bill

 

Will certainly post this in a new tread and explain the solution.

 

In the meantime, thanks for the inspiration for creating this workaround to update labels based on checkbox.

 

As I said, currently you cannot create filter on Jira Board or list based on checkbox, but you can update Labels on each checkbox change.

 

Cheers

 

On your_checkbox change

 

Variable = DisciplineLabel

{{#issue.your_checkbox}}"{{value}}"{{^last}},{{/}}{{/}}

 

Edit issue

 

{
"fields": {
"labels": [
{{DisciplineLabel}}
]
}
}

0 votes
Pramodh M
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 23, 2022

Hi @Daniel Helmstedt 

Welcome to the Community!!

If you have a predefined list of labels that's best, otherwise, it's not recommended.

Have the list of labels predefined, and going forward for once you need to create the label and add it in automation.

The Automation would go like this

Trigger - Issue Created

Condition - JQL Condition to check whether labels you manually added once is present in Summary/Description

Action - Add the label

Thanks,
Pramodh

Suggest an answer

Log in or Sign up to answer