The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Advanced Field Editing - Add/Remove labels using variable smart value

Kalyan Sattaluri
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 Champions.
December 4, 2023

Hi All,

My usecase is this ticket - https://community.atlassian.com/t5/Jira-Software-questions/Smart-values-for-copying-multiple-labels/qaq-p/1882892

 

I have a variable {{varLabels}}  which holds an array ["ABC", "DEF"] of labels I got from parent which I need to "add" to its stories.

When I go to advanced editing and I want to set the labels, the syntax suggested by @Bill Sheboy  works as expected, but when I try to add the labels instead, instead of individual labels, whole array gets added as 1 label.

 

 

{ "fields": { "labels": {{varLabels}} } }   <-- works

 

{ "update": { "labels": [ {"add": {{varLabels}}} ] } }   <-- throws an error that operation value must be a string

 

{ "update": { "labels": [ {"add": "{{varLabels}}"} ] } }   <-- does not work, updates complete array as single label.

 

 

I am thinking its cause the "add" method expects a single string based on documentation.. so I wanted to understand if there are any work arounds to this problem. Thanks!

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
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 Champions.
December 5, 2023

Hi @Kalyan Sattaluri 

Without seeing the specifics of your rule or audit log details...

Please review the syntax differences for setting versus adding labels with JSON, write your created variable to the audit log, and then adjust accordingly: https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/#Adding-labels

Kind regards,
Bill

Kalyan Sattaluri
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 Champions.
December 5, 2023

Thanks Bill, using your response from my other thread, I was able to format my JSON to "adding" & "removing" labels. You are AWESOME!

 

-----------------------------------

If my labels list were in a variable (mylabels), 

mylabels = 124, 345, ABC

 

I used your suggestion to format the JSON as below

[ {{#mylabels.split(", ")}}{ "remove" : "{{.}}" }{{^last}}, {{/}}{{/}} ]

which then gave output as:

[ { "remove" : "124" }, { "remove" : "345" }, { "remove" : "ABC" } ]

 

I then stored the output in a new variable (newVar).

Then i used advanced edit to remove the labels from the issue:

 

{
"update": {
"labels": {{newVar}}
}
}

 

NOTE: I tried a lot to use @Bill Sheboy  solution from here to format JSON the way he suggested but I keep getting JSON formating error. I am in Data center edition, I will keep trying that approach as well and edit this post if that route is also possible.

 

Like Bill Sheboy likes this
TAGS
AUG Leaders

Atlassian Community Events