Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How to copy multi-value field in using Advance Options in Automation Rule?

In an automation rule, created a sub-task and copying a multi-value field like labels/components/fix version etc. from Parent to the child sub-task

I tried both below to set labels from the Parent issue,

"labels": "{{issue.labels}}"

"labels": [ "{{#issue.labels}} {{.}}{{/}}"]

but if the parent has multiple values in the Labels field, it errors out

Error creating issue - The label 'Label1, Label2, Label3' contains spaces which is invalid. (labels)

Doing this graphically works but trying to achieve it via Advance options using JSON

How do you copy a multi-value field using Advance Options in Automation Rule?

any help is appreciated

~Arun

2 answers

5 votes
Erik Buchholz
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.
Jul 16, 2019 • edited Jul 27, 2021

The problem is, that you need to use the following syntax for arrays.

{
"fields": {
"labels": ["label_1", "label_2"]
}
}

You can achieve this syntax easy with the following smartvalues {{labels.asJsonStringArray}}

So one solution is the following code.

{
"fields": {
"labels": {{labels.asJsonStringArray}}
}
}

If you want to do it with the list syntax you can use the following code.

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

With this code you enclose every label with ' " ' and seperate them with ' , '

More information about the asJsonStringArray and similar options you can find at

https://docs.automationforjira.com/issues/edit-additional-fields.html#using-smart-values

there is also a reference for other fields like custom fields.

About the list options the reference is at

https://docs.automationforjira.com/reference/lists.html#list

PS: Thanks to Victor Seger from Automation for Jira for giving me the right input on my problem with a custom field.

Really helpful, thanks. But how do I add these Labels to existing labels? This currently removes existing labels

Like Erik Buchholz likes this
Erik Buchholz
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.
Jul 27, 2021 • edited

Hi @Daniel Oriold ,

that's right. "fields" is an alias for update > set, so you overwrite existing values. That's no problem if you create a new issue in the automation but may be, if you want to update an existing one.

If you want to add some labels, you need to use the update syntax like

{
"update": {
"labels": [{"add": "label_1"}, {"add": "label_2"}]
}
}

This syntax is a bit more complicated than the "fields" syntax, what makes us need to change the other code examples, too. I thought we could use the asJsonObjectArray("add") function to get it the simple way, but that doesn't give us anything.

So we need to use list syntax:

{
"update": {
"labels": [{{#labels}}{"add": "{{.}}"}{{^last}},{{/}}{{/}}]
}
}

Please note that this gives an error if the issue has no labels. To cover this case you could add an {"add":""} at the beginning and move the comma.

{
"update": {
"labels": [{"add":""}{{#labels}},{"add": "{{.}}"}{{/}}]
}
}

Regards

PS: If you like my answer, I'd appreciate if you upvote it. Thanks!

Like # people like this

Thank you very much! This was a great help :)

Awesome - such a small task however annoying! This solved it :D TY!

Like Erik Buchholz likes this

Thanks @Erik Buchholz  This was great.

Hey Erik, I am actually using a custom field call 'Segment' which is a Select List (multiple choices). I want the automation to copy the values in the Segment and add them as individual Labels to the Labels field. When I do this:

{
"update": {
"labels": [{"add":""}{{#segment}},{"add": "{{.}}"}{{/}}]
}
}

Then I get the following Error

('Field 'labels' cannot appear in both 'fields' and 'update')

Erik Buchholz
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.
Jul 27, 2021

Hi @Daniel Oriold ,

the error says that you still have labels in the fields part of the JSON. Is that just the old code or do you try to do something different there?

Regards

Like Daniel Oriold likes this

Super weird. Now all of a sudden it is working. You have no idea how helpful this is to so many of our users. Thanks so much. I wish I could buy you a beer...

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events