Custom Script Field Examples
This page contains a number of custom script field examples:
- Calculate a number based on other fields
- Show the total time this issue has been In progress
- Show the number of attachments the issue has
- Show all previous versions in a given project
- Display an information message
- Show the component lead
- Show multiple component leads
- Show the work remaining in linked issues
- Show the work remaining in all issues in an epic
Examples
For the examples below, you must first navigate to the Custom Script Field page:
- From ScriptRunner, select the Fields tab.
- Select Create Script Field.
- Select Custom Script Field.
- Create a custom script field based on the examples provided below.
Calculate a number based on other fields
You can calculate a number based on other fields. In the following example, we already have a number field called Severity, and we want a new value that is the product of the Priority and Severity:
Show the total time this issue has been In Progress
You can create a custom field that shows the total time an issue has been in the In Progress state—summing up multiple times if necessary:
Show the number of attachments the issue has
hasAttachments.
You can create a custom script field to show the number of attachments. This could easily be modified to show the number with a specific extension etc.
Show all previous versions in a given project
You can create a custom script field to display every version in a given project prior to the oldest fix version:
Display an information message
As an admin, you might want to display extra information about an issue, and not be able to search it. You can create a custom script field where your script can output HTML, and you effectively don't use a velocity template.
In the following example we want to draw attention to an issue when it is blocked by other issues that are not resolved, and not assigned.
The field appears as follows:
Show the component lead
As an admin, you might want to display the lead for the component selected for an issue, making use of the User display template.
The field appears as follows:
Show multiple component leads
As an admin, you might want to display all unique component leads for the component selected for an issue:
The field appears as follows:
Show the work remaining in linked issues
In this example, we create a custom script field to show the work remaining in issues that are blocked by other issues.
Sometimes you may break down tasks by usings a link type, such as Blocks, rather than using subtasks. However, when you do this you can't see the rolled up remaining estimate. The following custom field shows the amount of time remaining on all issues that this issue is blocked by, and includes any time remaining on the current issue.
is blocked by and the inbound link is Blocks. See the Atlassian documentation for Configuring issue linking if you want to create your own custom links.The field appears as follows:
Indexing
You may notice a further problem. When work is logged on one of the linked issues, the issues that link to it don't get reindexed, so a search won't return the correct results.
To handle this, we use a custom Script Listener to follow Blocks links and reindex those issues:
Show the work remaining in all issues in an epic
In this example, we create a custom script field to show the work remaining in all issues in an epic. We have other requirements for this script field:
- We only want this custom script field to display on Epic issues.
- We want to include sub-tasks of issues in an epic in the total work remaining.
- We want to include any time remaining on the epic itself.
Proceed with the example as follows: