Forums

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

Migrate issues using scriptrunner

Aisha M
Contributor
April 28, 2025 edited

Hi,

I am trying to migrate my projects to a new workflow scheme, which has an updated Sub-Task workflow. 

I have specified old status : new status mapping in the script. But, despite this, post migration, the sub-tasks are not working as expected (Though they are in the new workflow, they are behaving odd , like unable to move them through any status). We have used this same script to migrate other issue types without problem. Any thoughts on what we might be missing, or should sub-tasks be dealt differently ?

 

Here is a snippet of the logic, 

 

def subtaskMapping = [ "old" : "new" ]
JiraWorkflow subTaskWF = workflowManager.getWorkflow("New Sub Task Worklow")
projectkeys.each { projectKey ->

def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey as String) 
def oldWFScheme1 = ComponentAccessor.WorkflowSchemeManager.getWorkflowScheme(project) 
def oldWFScheme = oldWFScheme1?.name ? oldWFScheme1.name: ""
def source
if (oldWFScheme == "XYZ Workflow Scheme") {
source = ComponentAccessor.projectManager.getProjectByCurrentKey("TEST") //source project with new scheme
}

if(source){
if(project){

def issues = ComponentAccessor.issueManager.getIssueObjects(ComponentAccessor.issueManager.getIssueIdsForProject(project.id));

issues.each{issue ->

if(issue.getIssueType().getName() == "Sub-Task"){
def oldStatus =issue.getStatus().getName()
def newStatus = subtaskMapping[oldStatus]
if(newStatus){
Status destinationStatus = constantsManager.getStatusByNameIgnoreCase(newStatus);
workflowManager.migrateIssueToWorkflow(issue as MutableIssue, subTaskWF, destinationStatus)
}

ComponentAccessor.getWorkflowSchemeManager().removeSchemesFromProject(project); 
                    ComponentAccessor.getWorkflowSchemeManager().addSchemeToProject(project, ComponentAccessor.getWorkflowSchemeManager().getSchemeFor(source))

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Tuncay Senturk _Snapbytes_
Community Champion
April 28, 2025

Hi @Aisha M 

I'm well, nice to hear from you :)

I'm not sure if the problem is related to that but I'd suggest two things at first glance.

1. reindex the issue after the migration

if (newStatus) {
Status destinationStatus = constantsManager.getStatusByNameIgnoreCase(newStatus)
workflowManager.migrateIssueToWorkflow(issue as MutableIssue, subTaskWF, destinationStatus)


issueIndexingService.reIndex(issue)
}

 2. Not related to the problems but it's a best practice. I'd call removeSchemesFromProject and addSchemeToProject once per project (not issue). So I'd change

if(source){
  if(project){

to 

if (source && project) {

 I hope this helps

Aisha M
Contributor
April 28, 2025 edited

@Tuncay Senturk _Snapbytes_  Thank you for the reply ! That didn't make a difference. 

I think it appears like, the sub-task is showing the new workflow scheme in the project configuration, but while moving through statuses, it still seems to follow the status of the previous workflow . 

We have used the same script & logic to migrate Story, Bugs and few other issue types with no problem. Only sub-task seems to have this problem. 

 

Ironically, when I ran a different script to directly make changes to the workflow scheme. that seems to work and move the Sub-task. But that was not practical unfortunately, because, around 1000+ projects use the scheme and that ran for around 15hrs . . This method of moving projects to a different workflow scheme with the new workflow, along with the mapping took around 2 hrs max

Aisha M
Contributor
April 28, 2025

@Tuncay Senturk _Snapbytes_ I was able to figure out and it was such a silly mistake :D :D

It was supposed to be if(issue.getIssueType().getName() == "Sub-task") with a lower case "t" instead of "Sub-Task"  . .  I didn't know jira was this case sensitive :O

Like • Tuncay Senturk _Snapbytes_ likes this
Tuncay Senturk _Snapbytes_
Community Champion
April 29, 2025

Ohh!, I would not find that. Thanks for letting me know. Yes, Jira is sensitive and case sensitive :) 

Like • Aisha M likes this
0 votes
Piyush Annadate _ACE Pune_
Community Champion
April 28, 2025

Hello @Aisha M ,

Can you log 'Status destinationStatus = constantsManager.getStatusByNameIgnoreCase(newStatus); and provide us the details'

Need to Confirm: 

1. The status is correctly returned?
2. New workflow is published with required changes?

Aisha M
Contributor
April 29, 2025

@Piyush Annadate _ACE Pune_ Thank you for this suggestion. I was able to figure out the sub-tasks were not being processed only after adding logs. Definitely helped me pin point the problem :) 

0 votes
Aisha M
Contributor
April 28, 2025

Hello '@Antoine Berry  @Tuncay Senturk _Snapbytes_  Hope you are well and good !!!! :) I just wanted to know if you experts have any thoughts that might really help me :)

TAGS
AUG Leaders

Atlassian Community Events