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

Kevin Dalton December 29, 2016

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
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 Leaders.
December 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)
0 votes
Kevin Dalton December 30, 2016

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