Map Custom Field Values From One Field To Another


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!) 

1 answer

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
            , request

//place issue keyis list here
List<String> getIssues(){
    return Arrays.asList(
        , "key2"

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 09, 2018 in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

226 views 6 0
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