How do you copy component values to multi-select field?

How do you copy the component values from around 800 issues to a new multi-select custom field with the same values.

2 answers

1 vote
Vasiliy Zverev Community Champion Dec 30, 2016

Here is code to start with:

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField

Issue issue = ComponentAccessor.getIssueManager().getIssueObject("SN799-1")

CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Экземпляр")
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
Map<String, Option> options = new HashMap<>()
for (Option option: optionsManager.getOptions(customField.getRelevantConfig(issue)).getRootOptions()){
    options.put(option.getValue(), option)

List<Option> issueOptions = new ArrayList<>();

for(ProjectComponent component: issue.getComponentObjects()){

issue.setCustomFieldValue(customField, issueOptions)

Thanks for the code but we ended up getting them all updated using a CSV.  We will hang onto this code though as it will come in handy in the future.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Jira

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,096 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you