Hello,
We have a JIRA instance which has many administrators. As a result, we often have situations where users have created custom fields which have the same names.
I would like to merge similar custom fields into a single field. To do so, I need to be able to map the current values in the fields to be merged into the new values of the new merge field.
I thought I could do this by writing individual queries to locate issues that use a particular old field value and, then, use a Bulk Update to set the new field value. Once all of the values have been mapped into the new field, I can delete the old, redundant fields. It's a manual process, but it's doable because the number of old field values is not too great.
Unfortunately, the Bulk Update doesn't work because some of the issues are in a state that does not allow further updates.
I was thinking that the script runner may help. I noticed that there is a script runner script which copies values from one custom field to another. I'm assuming that script will bypass the restrictions against changing issues. How hard would it be to extend that script to perform a mapping operation instead of a direct copy? Is that something that anyone has considered?
(NOTE: I'm a complete script runner newbie, so the more detail, the better. Thanks!)
Here you are. Define custom field names and provide issue keis list. Magic! and all done!
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.UpdateIssueRequest import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.user.ApplicationUser IssueManager issueManager = ComponentAccessor.getIssueManager(); CustomField cf_from = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("custom_from_name") CustomField cf_to = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("cf_to_name") MutableIssue issue; UpdateIssueRequest request = UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build(); ApplicationUser curUser = ComponentAccessor.getJiraAuthenticationContext().getUser() for(String issueKey: getIssues()){ issue = issueManager.getIssueObject(issueKey); issue.setCustomFieldValue( cf_to, issue.getCustomFieldValue(cf_from) ) issueManager.updateIssue( curUser , issue , request ) } //place issue keyis list here List<String> getIssues(){ return Arrays.asList( "key1" , "key2" ) }
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.