How do you copy the component values from around 800 issues to a new multi-select custom field with the same values.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.