This documentation is for Insight for Server/Data Center only.

This page will describe the steps to migrate from the old deprecated custom field to the new "Insight Object/s" custom field.

1) Create a new custom field and configure it as you wish.

2) Re-index JIRA to get an updated index.

3) Take this snipped groovy script and change the custom field ids accordingly

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.web.bean.PagerFilter;

def projectManager = ComponentAccessor.getProjectManager();
def issueManager = ComponentAccessor.getIssueManager();
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def searchService = ComponentAccessor.getComponentOfType(com.atlassian.jira.bc.issue.search.SearchService);
def jqlQueryParser = ComponentAccessor.getComponentOfType(com.atlassian.jira.jql.parser.JqlQueryParser);

def deprecatedInsightCustomFieldId = .....; /* This should be the deprecated custom field id, should be 5 digits */
def newInsightCustomFieldId = .....; /* This should be the new custom field id, should be 5 digits */

/* Change the custom field id's accordingly to your environment and the custome fields you want to migrate */
def deprecatedInsightCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(deprecatedInsightCustomFieldId);
def newInsightCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(newInsightCustomFieldId);

def query = jqlQueryParser.parseQuery("cf[" + deprecatedInsightCustomFieldId + "] is not EMPTY");
def searchResults = searchService.search(currentUser, query, PagerFilter.getUnlimitedFilter());

log.warn("Issues to be updated: " + searchResults.getTotal());
searchResults.getIssues().each { issue ->
    MutableIssue mi = (MutableIssue) issueManager.getIssueObject(issue.getId());            
    def insightObjects = mi.getCustomFieldValue(deprecatedInsightCustomField);
    if (insightObjects != null && !insightObjects.isEmpty()) {
        mi.setCustomFieldValue(newInsightCustomField, insightObjects);
        ComponentAccessor.getIssueManager().updateIssue(currentUser, mi, EventDispatchOption.DO_NOT_DISPATCH, false);    
            
        log.warn("Changed issue: " + mi + ", set new custom field with values: " + insightObjects);
    }   
}

4) Copy this script with the changed custom field ids to the Insight web console.

5) Run the script and check the log for any details about the update issues.

6) Add the new field on the same screens as the previous one.

7) Check that you have the same objects as the old field

That's it!

This script will update the history of the issue, and the update date, but will not fire any update event due to the "EventDispatchOption.DO_NOT_DISPATCH"