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: 

It it possible to bulk move issues in Jira cloud using script runner?

Angel Mosqueda
March 13, 2025

Im trying to bulk move issues in Jira cloud using script runner. I created a script to move the issues but they are not actually moving even though my logs say they were successfully moved. 

 

 

 

def targetProjectKey = "AT2"
def issueKeys = ["AT1-12", "AT1-13","AT1-15","AT1-16","AT1-17"]


// Initialize the logger
logger.info("Starting bulk move of issues to project: ${targetProjectKey}")

// Function to get issue details

def getIssueDetails(issueKey) {
    def issue = get('/rest/api/3/search')
        .queryString('jql', "project = 'AT1'")
        .queryString("expand", "key")
        .asObject(Map)

    if (!issue) {
        logger.error("Issue ${issueKey} not found")
        return null
    }
   
    return [
        key: issue.body.key,
        id: issue.body.id,
        typeId: issue.body.issueTypeId,
        //summary: issue.body.summary
    ]
}

// Function to move an issue using REST API
def moveIssueToProject(issueKey, targetProjectKey) {
    logger.info("Moving issue ${issueKey} to project ${targetProjectKey}")
   
    try {
        // Get issue details first
        def issueDetails = getIssueDetails(issueKey)
        if (!issueDetails) {
            return [success: false, message: "Issue not found"]
        }
       
        // Prepare request body
        def requestBody = [
            fields: [
                project: [
                    key: targetProjectKey
                ]
            ]
        ]
       
        // Make REST API call to update the issue
        def response = put("/rest/api/2/issue/${issueKey}")
            .header("Content-Type", "application/json")
            .body(requestBody)
            .asJson()
       
        if (response.status == 204 || response.status == 200) {
            logger.info("Successfully moved issue ${issueKey} to project ${targetProjectKey}")
            return [success: true, message: "Successfully moved issue"]
        } else {
            logger.error("Failed to move issue ${issueKey}. Status: ${response.status}, Body: ${response.body}")
            return [success: false, message: "Failed to move issue: ${response.body}"]
        }
    } catch (Exception e) {
        logger.error("Exception while moving issue ${issueKey}: ${e.message}")
        return [success: false, message: "Exception: ${e.message}"]
    }
}

// Main execution
def results = []

// Process issues in the specified order
issueKeys.each { issueKey ->
    def result = moveIssueToProject(issueKey, targetProjectKey)
    results.add([issueKey: issueKey, result: result])
   
    // Add a small delay to prevent rate limiting
    sleep(500)
}

// Return results
return results

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Marc -Devoteam-
Community Champion
March 13, 2025

Hi @Angel Mosqueda 

Why use scriptrunner, this is an ootb function.

https://support.atlassian.com/jira-software-cloud/docs/move-multiple-issues/ 

You could ask the app support department, but probably its not a function on the app as Jira offers this ootb

Angel Mosqueda
March 13, 2025

Im using script runner because I need to control the order in which the issues are moved. for example( AT1-12-> AT2-1, AT1-13 ->AT2-2, At1-15 ->AT2-3)

The order that they are created is important so I'm trying to use scriptrunner to achieve this.

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events