How do I extract data from a multiselect custom field and populate each value as a label using JIRA
Asked by Doug Slay:

I have a custom field that displays a list of client codes. This field is a multi-select field. Using JIRA automation, I want to take each selected client code for that issue and insert that client code as a Label on the same issue.


Answers:
author: Darryl Lee
body: Hi! You can do this iterating through all of the multi-select values [as a list](https://support.atlassian.com/jira-software-cloud/docs/smart-values-lists/) and using [advanced field editing](https://support.atlassian.com/jira-software-cloud/docs/advanced-field-editing-json/) to update them.

Here's what I tested putting into **Additional fields**, where my multi-select field is named "multi":

```
{
? ?"fields": {
? ? ? "labels": [
? ? ? ? ?{{#issue.multi}}"{{.}}"{{^last}},{{/}}{{/}}
? ? ? ]
? ?}
}
```

I'm not sure why I cannot include a screenshot of my rule, but I just got this to work.

comments: author: Darryl Lee
body: Screenshot: <https://photos.app.goo.gl/Zog8u8uEq3sqAmwj6>


author: Doug Slay
body: Thanks Daryl, but I am not seeing the results on my end. I copied this code and placed it in the Additional Fields. The automation runs and says it is successful, but the Label field has not been updated with the Client Code(s) values. Am I missing a step?


author: Doug Slay
body: Should I update this code to reflect the custom field (Client codes) I want to use as the source?

```
{
? ?"fields": {
? ? ? "labels": [
? ? ? ? ?{{#issue.multi}}"{{.}}"{{^last}},{{/}}{{/}}
? ? ? ]
? ?}
}
```


author: Darryl Lee
body: Yes, "multi" needs to be replaced with the name of your custom field. If it has spaces, you would use:

```
? ? ? ? ?{{#issue."Your Custom Field Name"}}"{{.}}"{{^last}},{{/}}{{/}}
```

And in some cases, that format doesn't always work either, so you might need to use:

```
? ? ? ? ?{{#issue.customfield_10034}}"{{.}}"{{^last}},{{/}}{{/}}
```

There's several ways to find the ID for the custom field: [How to find custom field ids in jira](https://community.atlassian.com/t5/Jira-questions/How-to-find-custom-field-ids-in-jira/qaq-p/233860)


author: Doug Slay
body: Sorry Daryl. I just reread your message and it works GREAT. Thanks you!


author: Doug Slay
body: One last question Daryl. If I want to populate the Label field from 3 different custom fields is that possible? I want the values from Client Code(s), Service Team and Assigned Product to all be populated as individual labels on the issue.


author: Doug Slay
body: I am assuming this in incorrect.

{  
"fields": {  
"labels": \[  
{{#issue.customfield_12100}}"{{.}}"{{\^last}},{{/}}{{/}} , {{#issue.customfield_13731}}"{{.}}"{{\^last}},{{/}}{{/}} , {{#issue.customfield_13732}}"{{.}}"{{\^last}},{{/}}{{/}}  
\]  
}  
}


author: Darryl Lee
body: Hi Doug - yes, that looks right to me. By the way, I always test my rules by using a Manual Trigger that is only visible to me (administrator or site-admin group, for instance.)

<https://support.atlassian.com/jira-software-cloud/docs/manually-run-a-rule-against-an-issue/>

Then I can create a single test issue, add all the values I want to the custom fields, and then manually run it. If needed, I can clear the Labels on that issue and then try it again.

OH, I should note that using that code will **replace**any other labels. If you wanted to update, you would need to use something like:

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

But I'm not sure Automation will do the right thing with those extra { } around the "add" clauses.


author: Claire Berry
body: Hi [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322)   

I'm wondering if you can help me with similar.   

I have a multi select insight custom field, that I want to populate with all its values when an issue is created.  

I've used the below code before to set a value of an insight custom field with a certain object which works:  

```
{

????"fields": {

????????"customfield_25007": [{"key" : "PPBCMDB-239336"}]

????}

}
```

<br />

I tried following your instructions above, not sure if the works on insight custom fields.   

This is what I tried:  

<br />

{  
"fields": {  
"customfield_32970": \[  
{{#issue.customfield_32970}}"{{.}}"{{\^last}},{{/}}{{/}}  
\]  
}  
}

<br />

But doesn't seem to work. Do you know if this works for insight fields, or if I need to add the key in somewhere for it to work.


author: Darryl Lee
body: Hi - back in [April 2021](https://community.atlassian.com/t5/Jira-questions/Re-Re-Rule-to-set-Insight-field-value-in-Automation-for/qaq-p/1669644/comment-id/479633#M479633), new automation blocks were introduced for Insight including an action block to let you edit Insight fields attributes:

![](https://confluence.atlassian.com/jirasoftwarecloud/files/993927647/1044108162/1/1614758331959/Edit+Insight+fields.png)

<https://support.atlassian.com/jira-software-cloud/docs/automation-actions/#Automationactions-EditInsightfieldattributes>

Hopefully this is what you need?


author: Claire Berry
body: Hi Darryl,   

Thanks for the reply.   

I am not on cloud, so don't have these options. We are on Data Centre.  

And it isn't the attributes I am trying to update.   
It's an Insight Custom field, that I am trying to populate with all it's options.   

I can set it on the request level and use a preset value and hide it, but the issue with this is that the insight object will update overtime, so I would need to update the preset value each time a new one was added.   

Not sure if I am making sense :)   

It's similar to the query above, instead it's an insight custom field instead of a multi select field and I want to populate the values into its own field, rather than copying to another.


author: muneet.bakshi
body: [@Doug Slay](/t5/user/viewprofilepage/user-id/3130199) and [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) , I am trying to do the same thing but I need to use automation to keep my labels and multi select field matched. For example if I have:

Field A (Multiselect):

Value 1

Value 2

I want to create a labels:

Value1

Value2

And when Value 2 is removed from Field A I want to remove it from the labels. Any idea how I can accomplish this? Any help would be greatly appreciated.


Tags: label