Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,366,701
Community Members
 
Community Events
168
Community Groups

Automation - Set ticket Labels from a Variable

Edited

Hi 

I have a set of Labels in my ticket (a,b,c).  In my automation I would like to save my labels in a temporary Variable (New Action > Advanced > Create Variable) and, at some point in the flow, restore these Labels according with conditions.

When I create the Variable I assign the value to a TMPLABEL as per below

{{issue.labels.join(",")}} // comma separated string

Var.png

or

{{issue.labels.asJsonString.asJsonArray}} // Array

VarJson.png

In the Edit Issue step I try with

{
  "fields": {
     "labels": [
       {{#TMPLABEL}}{{.}}, {{/}}
     ]
  }
}

Loop_01.png

When the automation runs I get the error "Error while parsing additional fields. Not valid JSON."

Any idea?

Thanks

--

Federico 

 

 

 

 

 

1 answer

1 accepted

0 votes
Answer accepted
Hana Kučerová Community Leader Jan 13, 2021

Hi @Federico Zanetti ,

please try

{{issue.labels.asJsonStringArray}}

and

{
"fields": {
"labels": {{#TMPLABEL}}{{.}}{{/}}
}
}

The problem with 

{{#TMPLABEL}}{{.}}, {{/}}

 is there will be comma after all labels (including the last one) and also the quotes will be missing - so this will result in something like:

label1, label2, label3,

But we need to create:

"label1", "label2", "label3"

I don't like my solution much, but this only combination worked for me.

Like Tessa Tuteleers likes this

Hi @Hana Kučerová,

it works perfectly!

Thanks

--

Federico

Hi @Hana Kučerová,

on the same topic, what if I would like to restore a label according with a condition.

For instance, I have three labels "MY_PIZZA, YOUR_PIZZA, MY_CAKE" saved in a Variable and I would to restore just labels including "PIZZA" 

Following the example in the documentation, the most reasonable solution seems

{{#if(TMPLABEL.indexOf("_PIZZA").gt(0)) }}
{{.}}
{{/}}

However, when I run the automation, I get an error as per below

Error editing issues (data was not an array (labels))

Any thought?

Thanks

--

Federico

Hana Kučerová Community Leader Jan 15, 2021

Hi @Federico Zanetti ,

I don't know about your use case much, but wouldn't it be possible to use automation conditions and action (Edit issue -> Labels -> Add/remove values) instead of working with variable?  It seems to me very complicated and after some time it will be hard to determine, what is your automation rule exactly doing.

Like Federico Zanetti likes this

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events