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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
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.
Awesome - such a small task however annoying! This solved it :D TY!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Erik Buchholz This was great.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
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.