Hi, I created automation that creates child issue under the trigger issue and inherit all of its labels. Then I need it to remove all of the labels starting with word "Create" (e.g. "CreateTask", "CreateStory",...).
I tried multiple approaches but nothing works. Closest I got was using smart value in advanced editing JSON like this, but still did not work:
{ "update": { "labels": [ { "remove": {{#issue.Labels.name.startsWith("Create")}} } ] } }
Hi @Branislav Toman -- Welcome to the Atlassian Community!
I believe this would need to be done in two steps: filter out the labels starting with "Create" and store the result in a variable, and add the remainder with JSON syntax when the issue is created.
{{#issue.labels}}{{#if(not(startsWith("Create")))}}{{.}},{{/}}{{/}}
This works by iterating over the labels and removing any which start with "Create", adding a comma-separator after any values found.
{{#if(exists(varLabelsToAdd))}}
{
"update": {
"labels": [
{{#varLabelsToAdd.substringBeforeLast(",").split(",")}}
{ "add": "{{.}}" }{{^last}},{{/}}
{{/}}
]
}
}
{{/}}
Then use the variable, dropping the last comma, and splitting the remainder to dynamically build the JSON. As a precaution, I added a conditional logic around that to ensure there are labels to add.
As an aside, you could also try using a regular expression with the match() function to remove the labels in one step. However, and in my experience, that may not be possible as the "underlying implementation is based on Java's Pattern class" but does not support all of its features.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.