Forums

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

script move

Divya
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 6, 2026
import com.atlassian.jira.workflow.JiraWorkflow
import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.status.Status
import groovy.transform.*
import com.atlassian.jira.workflow.migration.DefaultMigrationHelperFactory
import com.atlassian.jira.task.TaskProgressSink
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.bc.workflow.WorkflowSchemeService
import org.apache.log4j.Logger
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.bc.project.index.ProjectReindexService
import com.atlassian.jira.workflow.WorkflowSchemeManager
import com.atlassian.jira.workflow.AssignableWorkflowScheme





IssueManager issueManager = ComponentAccessor.getIssueManager()
def workflowSchemeService = ComponentAccessor.getComponent(WorkflowSchemeService)
def migrationHelperFactory = ComponentAccessor.getComponent(DefaultMigrationHelperFactory)
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
def projectReindexService = ComponentAccessor.getComponent(ProjectReindexService)
def assignableWorkflowScheme = ComponentAccessor.getWorkflowManager()
def constantsManager = ComponentAccessor.getConstantsManager();

 

final def csvFileFullName = "var/atlassian/jirasharedhome/scripts/bulkUpdates/Delivery.groovy"
def projectkeys= []
def file = new File(csvFileFullName)
file.eachLine { line ->
    projectkeys.add(line.trim())
    log.warn("Loaded project key: ${line.trim()}")
}

 

 
def containerMapping = ["Funnel":"To Do","Analyzing":"To Do","Ready backlog":"To Do","Implementing":"Working","Cancelled":"Cancelled","Done":"Done"]
def dependencyMapping = ["Open":"To Do","Mitigating":"Working","Planned":"Ready to Work","Working":"Working","Cancelled":"Cancelled","Remediated":"Done"]
//def ImpedimentMapping = ["Funnel":"identify","Analyzing":"Analyzing","Ready Backlog":"Analyzing","Implementing":"Monitoring","Cancelled":"Cancelled","Done":"Done"]
def riskstatusMapping = ["Funnel":"identify","Analyzing":"Analyzing","Ready Backlog":"Analyzing","Implementing":"Monitoring","Cancelled":"Cancelled","Done":"Done"]
//def planningMapping = ["Backlog":"To Do","Pre-Planning":"To Do","Planning":"To Do","Ready for Planning":"To Do","Sub-Domain Working":"Working","Cancelled":"Cancelled","Validated & Accepted":"Done","Delivered":"Done"]

 

def workflowManager = ComponentAccessor.getWorkflowManager()

 

JiraWorkflow dependencyWF = workflowManager.getWorkflow("UNI Dependency Workflow")
JiraWorkflow riskWF = workflowManager.getWorkflow("UNI-Risk workflow")
JiraWorkflow conWF = workflowManager.getWorkflow("UNI Container Workflow")
//JiraWorkflow objWF = workflowManager.getWorkflow("UNI Objective workflow")
 

 

//source initialized if individual project's workflow scheme needs to be updated
//def source = ComponentAccessor.projectManager.getProjectByCurrentKey("UPRTP")
projectkeys.each { projectKey ->
                              //projectKeys.add(projKeys)
                      log.info("Going to find source for project "+projectKey)        
                      def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey as String) //Get the project key of project to be migrated over
                      def oldWFScheme1 = ComponentAccessor.WorkflowSchemeManager.getWorkflowScheme(project) //Get the workflow scheme of the project to be migrated
                      def oldWFScheme = oldWFScheme1?.name ? oldWFScheme1.name: ""
                      log.info("old workflow scheme is-" + oldWFScheme+"-")
                      def source
                     
                        if (oldWFScheme == "test - Required Statuses") {
                        source = ComponentAccessor.projectManager.getProjectByCurrentKey("Test1") //source scheme for above WF scheme
                        }
                       

 

                                         
                        else {
                        log.info("No workflow migration for this project key " + projectKey)
                        }
                             
                  if(source){  
                     if(project){

 

                    def issues = ComponentAccessor.issueManager.getIssueObjects(ComponentAccessor.issueManager.getIssueIdsForProject(project.id));
                        //log.warn("Total issues fetched = ${issues.size()}")  
                    issues.each{issue ->  
                        //log.warn("Checking issue ${issue.key} of type ${issue.issueType.name}")
                            if(issue.getIssueType().getName() == "Dependency"){
                          def oldStatus =issue.getStatus().getName()
                          def newStatus = dependencyMapping[oldStatus]
                          def sourceStatus = oldStatus
                          if(newStatus){
                       
                          Status destinationStatus = constantsManager.getStatusByNameIgnoreCase(newStatus);
                          workflowManager.migrateIssueToWorkflow(issue as MutableIssue, dependencyWF, destinationStatus)
                         
                        }  

 

                        }
                          else if(issue.getIssueType().getName() == "Container"){
                          def oldStatus =issue.getStatus().getName()
                          def newStatus = containerMapping[oldStatus]
                          if(newStatus){
                           Status destinationStatus = constantsManager.getStatusByNameIgnoreCase(newStatus);
                          workflowManager.migrateIssueToWorkflow(issue as MutableIssue, conWF, destinationStatus) //migrate the status
                         
                        }  

 

                        }

 

                    /* else if(issue.getIssueType().getName() == "Planning Increment"){
                          def oldStatus =issue.getStatus().getName()
                          def newStatus = planningMapping[oldStatus]
                          if(newStatus){
                           Status destinationStatus = constantsManager.getStatusByNameIgnoreCase(newStatus);
                          workflowManager.migrateIssueToWorkflow(issue as MutableIssue, objWF, destinationStatus) //migrate the status
                         
                        }  

 

                        }*/

 

  /*else if(issue.getIssueType().getName() == "Impediment"){
                          def oldStatus =issue.getStatus().getName()
                          def newStatus = ImpedimentMapping[oldStatus]
                          if(newStatus){
                           Status destinationStatus = constantsManager.getStatusByNameIgnoreCase(newStatus);
                          workflowManager.migrateIssueToWorkflow(issue as MutableIssue, featureWF, destinationStatus) //migrate the status
                         
                        }  

 

                        } */
                         if(issue.getIssueType().getName() == "Risk"){
                          def oldStatus =issue.getStatus().getName()
                            log.error("Step 8 ${issue.getIssueType().getName()}")
                          def newStatus = riskstatusMapping[oldStatus]
                           log.error("Step 9 ${oldStatus} to ${newStatus}")
                          if(newStatus){
                       
                          Status destinationStatus = constantsManager.getStatusByNameIgnoreCase(newStatus);
                          workflowManager.migrateIssueToWorkflow(issue as MutableIssue, riskWF, destinationStatus)
                                                   
                        }
                       
                        }
                }
                    ComponentAccessor.getWorkflowSchemeManager().removeSchemesFromProject(project); // remove the current workflow scheme
                    ComponentAccessor.getWorkflowSchemeManager().addSchemeToProject(project, ComponentAccessor.getWorkflowSchemeManager().getSchemeFor(source)) // add workflow scheme as per current source

 

                  }
                           }

 

}

1 answer

0 votes
Carlos Garcia Navarro
Community Champion
February 6, 2026

Hi @Divya ,

Do you have a specific question about this script?

Suggest an answer

Log in or Sign up to answer