Forums

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

Add issue labels from custom field

Simon Jones October 28, 2024

I'm trying to copy values from a custom field and add them to the Labels field on the same issue. The custom field type is: Select List (multiple choices)

 

Trigger

Value changes for Custom Field (any changes)

 

Create variable

Variable name: customField

Smart value:

{{issue.customfield_12345.value.replace(" ", "_")}}

This replaces spaces with underscores because the custom field allows values with spaces but the Labels field doesn't.

 

Edit issue fields

More options:

{
"fields": {
"labels": [
{{#customField.split(", ")}}
{ "add": "{{.}}" }
{{^last}},
{{/}}
{{/}}
]
}
}

Based on these threads I was expecting this to split the value into comma separated strings, then loop adding each one to the labels field. However, the audit log returns the error:

Error editing issues ID-1234 (Specify an string at index 0 for labels (labels))

 

Any thoughts appreciated - many thanks!

1 answer

1 accepted

1 vote
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 Leaders.
October 28, 2024

Hi @Simon Jones 

First thing, I recommend always prefixing variable / table names in rules to avoid any problems with smart value name confusion.  For example, using varCustomField instead of customField for the variable name.

Next, when using the "add" with the labels field in JSON, please use the "update" rather than the "fields" syntax: https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/

If that does not solve this...if you write that variable to the audit log and test your rule, what does it contain?  Is it what you expected.

Finally, when you create that variable, I recommend not allowing the rule to implicitly select what the delimiter should be for the list of values.  Instead, take control of it to ensure it works as expected.  For example: 

{{issue.customfield_12345.value.replace(" ", "_").join(", ")}}

 

Kind regards,
Bill

Simon Jones October 28, 2024

Replacing "fields" with "update" did the trick - thank you @Bill Sheboy!

Like # people like this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events