Snippets

Adaptavist Jira Cloud - Scripted Field to show Sprint Start and End Date

Created by Kristian Walker
/*
* This example script field script should configured to display on the 'Issue Sidebar' using a 'Text' return type and shows how to get the start date and end date from the active sprint and to display this inside a script field. 
* "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." 
*/

// Fetch the issue object from the key using the Jira Software API
def issue = get("/rest/agile/1.0/issue/${issue.key}")
        .header('Content-Type', 'application/json')
        .asObject(Map)
        .body

// Check if the issue is in a sprint and if so if the sprint is an active sprint
if (issue.fields.sprint && issue.fields.sprint.state == 'active') {

// Get the sprint start and end date strings from the API
    String sprintStartDate = issue.fields.sprint.startDate
    String sprintEndDate = issue.fields.sprint.endDate

// Format the date strings into a nicer format
    String formattedSprintStartDate = sprintStartDate.substring(0, 10)
    String formatterSprintEndDate = sprintEndDate.substring(0, 10)

// Set the dates in the scripted field
    return "Sprint Start Date: ${formattedSprintStartDate} Sprint End Date: ${formatterSprintEndDate}"

// Return a default message if the issue is not in active sprint
} else {
    return "The ${issue.key} issue is not currently in an active sprint"
}

Comments (0)

HTTPS SSH

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