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

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()){
    issueOptions.add(options.get(component.getName()))
}

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,990 views 12 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot