Snippets

Adaptavist Jira Cloud Script Console Extract Release Date for an Issue Version and Set Due Date to this Date.

Created by Kristian Walker
/*
 * "This script console script can be ran on the Script Console inside of Jira Cloud to show how you can select the release date for a specified version and set the due date to this date. 
 * All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner 
 * license shall be granted a  non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed
 * or amended and must be included in any circumstances where the code snippet is shared by You or a third party." 
 */
 
 // specify the issue key
def issueKey = '<IssueKeyHere>'

// Specify the name of the version to extract from the issue
def versionName = '<VersionNameHere>'

// Get the issue object
def result = get('/rest/api/2/issue/' + issueKey)
        .header('Content-Type', 'application/json')
        .asObject(Map)

// find the version specified on the issue and extract its version 
def versionReleaseDateString = result.body.fields.fixVersions.find {  it.name == versionName }.releaseDate

// Parse the extracted date string into a date object that can be set as the due date
def  versionReleaseDate = new Date().parse("yyyy-MM-dd", versionReleaseDateString)

// Update the issue to set the due date to the extracted versionReleaseDate value
def updateDueDate = put("/rest/api/2/issue/${issueKey}")
            .header('Content-Type', 'application/json')
            .body([
            fields: [
                    // Set the due date to the versionReleaseDate in the format which Jira expects the date to be in
                    duedate: versionReleaseDate.format('yyyy-MM-dd') as String
            ]
    ])
            .asString()
            
// Check if the issue updated correcly and if so return a success message            
if (updateDueDate.status == 204){
    return "Due date succesfully Updated"
} else {
    return "Failed to find issue: Status: ${result.status} ${result.body}"
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.