You can customise how information for an issue is displayed by using ScriptRunner Scripted Fields. These allow you to display information that would otherwise be unavailable for an issue by calculating, or amalgamating, data from one or more existing fields. You are, therefore, able to display a calculated custom field using ScriptRunner scripts which run when an issue is viewed. It is good practise to keep the scripts as simple as possible to reduce loading time. Scripted Fields display in the New issue-view.

Issues containing a scripted field will not show up in a JQL search until they have been viewed in a browser. This is because running the JQL search does not run the field on an issue as a value trigger.

Currently, scripted fields cannot be selected as columns in search results.

Create a Scripted Field

  1. Navigate to ScriptRunner → Scripted Fields.

  2. Click Create New Scripted Field.

  3. Enter the name of the field in Field Name. NOTE: The Identifier field shows the unique identification key for the new scripted field.

  4. Under Field Status, choose either Enabled or Disabled. When set to Enabled, the scripted field is active (on relevant issues/projects) as soon as it has been saved.

  5. Select the Location the issue view where the new scripted field should appear, either the Issue Content panel or Issue Sidebar. To view scripted fields in the sidebar, click Open Scripted Fields.

    Scripted fields in the issue content may not appear by default when an issue is loaded. To view the scripted fields click the ScriptRunner icon under the issue summary.

  6. Select one or more projects in Project/s. The scripted field only displays on the project/s specified.

  7. Select all Issue Type/s where you want the scripted field to display.

  8. Select the Field Type of your scripted field. Ensure you pick the correct field type for the data returned by your script. See Return Types for more information.

  9. (Optional) Enter a Search Term if you want to use Scripted Fields when searching for issues with JQL. There are several conditions that must be met for Search Terms, including: they must be unique, case sensitive, and contain no whitespace. They cannot match any ScriptRunner reserved keywords, ScriptRunner Enhanced Search functionsor JQL reserved keywords. Existing search terms/Jira custom field names cannot be used. 
  10. Enter a Script to Execute. This script is triggered when an issue is loaded. See Currency Conversion Number Field for a script example.

    Scripted fields in Jira Cloud do not dynamically update. The script triggers on issue load; therefore, changes to the field value are not reflected instantly, the issue must be reloaded.

  11. Enter an issue key in Test Against Issue to test the scripted field before saving.

  12. Click Save.

    Any changes to the Scripted Field configuration will require a re-test.

Return Types

The script for your field must return the correct data type.

For a text field, the script must return a single line String (no newline characters).

// This is OK
return "Hello World"
// This is not OK
return "Hello\nWorld"

For a number field, the script must return a numeric type, for example an Integer, Long, Float, Decimal, or BigDecimal.

For a date field, the script must return a LocalDate.

import java.time.LocalDate
import java.time.Month
return LocalDate.of(2020, Month.JUNE, 25)

For a datetime field, the script must return a ZonedDateTime.

import java.time.LocalDate
import java.time.LocalTime
import java.time.Month
import java.time.ZonedDateTime
import java.time.ZoneId
import java.time.ZoneOffset
// or
return ZonedDateTime.of(LocalDate.of(2020, Month.JUNE, 25), LocalTime.of(13, 45, 0), ZoneOffset.ofHours(-3))