Display the Sprint End Date
Scenario
You require a field that displays the date the issue’s Sprint ends.
Resolution
This solution uses the Scripted Datetime custom field type which displays the end date of the issue’s Sprint. The custom field is also configured to use the Sprint value as a dependency - if that value is changed, the custom field will automatically be recalculated!
Note: the configuration detailed below uses the Sprint field as both a dependency and within the script itself; however, in order to access the field value within the script, you must reference the field by the field name (e.g. customfield_10020
in this instance) instead of its label (“Sprint”). To find the field name, check the Dependencies field where the Sprint field is listed with its field name in parentheses (Figure 1, below). You need to use this value in the script!
You are viewing the documentation for Jira Cloud.
On This Page |
---|
Watch the Video
Follow the Steps
1. Create a Scripted datetime custom field
Log into your Jira instance as an Administrator.
In the upper right corner of the window, click Settings ( ) and select Apps.
In the left-hand sidebar, click Jira Misc Custom Fields.
Click My custom fields and in the upper right corner click New custom field.
Enter a name for your custom field and, optionally, a description.
Select Scripted datetime and click Next.
Select the screens to which the new custom field should be added. Click Next.
Configure the field (Figure 2, right):
In the script editor, enter the following:
// identify the sprints to which this issue is assigned (or an empty list if not assigned) const sprints = (await api.issue.getField(issue, "customfield_10020")) || [] // write the returned sprints to the console for debugging console.log("sprints:",JSON.stringify(sprints,null,2)) // locate the first active sprint const activeSprint = sprints.find((sprint)=>sprint.state==='active') // report the end date of the active sprint (if found, null otherwise) return activeSprint?.endDate
In the Dependencies on other fields field, select
Sprint
.
Optionally, you can test the results of the script by entering an issue ID in the Test with issue field and clicking Test.
Click Save.
2. Configure Custom Field Context (Optional)
When a custom field is created, it is added to the selected screens, but it is also added to every issue type and every project. If a custom field should only be added to specific issue types and/or projects, you need to edit the custom field context.
Open the custom field configuration:
From the My Custom Fields page, click the Contexts link for the new custom field.
Through the native Jira menus:
In the upper right corner of the Jira window, click Settings ( ) and select Issues.
In the left-hand panel, click Custom fields.
Locate your new custom field in the list and click Action at the far right. Select Contexts and default value.
Update the context for your custom field as necessary:
To add a new context, click Add new context.
To update the existing context, click Edit context or Edit Configuration.
For specific steps on modifying contexts, see this page: https://support.atlassian.com/jira-cloud-administration/docs/edit-a-custom-field-context/