The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Migrate Insight objects (multiple) (legacy) custom fields to Insight objects custom fields

This Community post provides a possible workaround to migrate Insight objects (multiple) (legacy) custom fields to Insight objects custom fields.

The Groovy script can be executed, for example from the Insight Script Console

It has been tested in Jira 8x

You should plan a maintenance window when you are migrating the fields in order to have a clean and effective migration without interruptions.

Groovy code example:

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;
import com.atlassian.jira.issue.search.SearchResults;

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 = *****;
def newInsightCustomFieldId = *****;

/* 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.getResults().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);
}
}

 

Result

We migrated from "MigrateSourceMultiple" custom field to "Insight New"

Screenshot 2022-02-22 at 16.15.31.png

0 comments

Comments for this post are closed

Community moderators have prevented the ability to post new comments.

TAGS
AUG Leaders

Atlassian Community Events