Snippets

Adaptavist Script Console Update An Issue And Set The Due Date Jira Cloud

Created by Kristian Walker last modified
/*
 * This console script updates an issue and sets the due date to the current date plus a number of days specified. 
 * "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 to update
def issueKey = '<IssueKeyHere>'

// Get todays date to set as the due date
def today = new Date()

// Update the issue
def result = put('/rest/api/2/issue/' + issueKey)
        .header('Content-Type', 'application/json')
        .body([
        fields:[
                //set the due date to todays date plus 2 days - speficy the  days to add in the plus() method call
                // Note you can update a Date Picker custom field by replacing 'duedate' with the custom field id such as customfield_10078
                duedate: today.plus(2).format('yyyy-MM-dd') as String
        ]
])
        .asString()
        
// Validate the issue updated correctly        
if (result.status == 204) {
    return 'Success - The issue has been updated with a new due date'
} else {
    return "${result.status}: ${result.body}"
}

Comments (0)

HTTPS SSH

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