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: 

Update Custom Field with multiple choice - ScriptRunner

Daniel Sørensen
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 18, 2025

Hi Everbody,

I want to update a CustomField that have multiply choice.

When I do an update on a Custom Field with only a single choice, I am doing this:

 

issue.update{ setCustomFieldValue(12606,"Some text")} - its working.
But If I want to update a field that can contains more the one value, I don't know how. I have tried this:

 

issue.update{ setCustomFieldValue(12603,["Some text", "Another text")}
But its not working.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Matt Parks
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.
March 18, 2025

When I've needed to do this, I create a Collection<String> variable, populate that variable with the necessary values, and then update the custom field with that variable.

For example, I have a script listener that takes all of the values for a multi-select field in all of the issues linked to one issue. Then I populate that same field on the one issue with all of the collected values. Here's the code snippets that are applicable:

 

Collection<String> deployDBImpList = [] (that's open and closed brackets to create an empty Collection)
def dbImpField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Databases Impacted").first()
linkDBImpValues = mutIssue.getCustomFieldValue(dbImpField) as Collection<String>  (this gets all of the values from the Databases Impacted field from one of the linked issues. This is part of an 'each' function that cycles through all of the linked issues)
if (linkDBImpValues?.size() != 0 && linkDBImpValues !=null)
    {
        deployDBImpList.addAll(linkDBImpValues)
    }
The above line adds all of the values from the linked issue into the original Collection
deployDBImpList = deployDBImpList.unique()
issue.setCustomFieldValue(dbImpField, deployDBImpList)
These two lines get rid of any duplicates and then populate the field on the main issue with the values from all of the linked issues.
Matt Parks
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.
March 18, 2025

Sorry about the formatting. I put my comments in italics. The code is in normal text.