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

This widget could not be displayed.
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()){
    issueOptions.add(options.get(component.getName()))
}

issue.setCustomFieldValue(customField, issueOptions)
This widget could not be displayed.

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
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

152 views 1 3
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