Skip to main content

Write the field script

Add or change the script of a scripted custom field. The script belongs to one field context, so a field with two contexts has two scripts.

Applies to: Script Master for Jira Β· Cloud

Before you begin​

Open the field context​

  1. In Script Master, open the Custom Fields tab.

  2. In the field's row, open Actions and select Contexts and default value. Jira's page with the field's contexts opens in a new tab.

  3. In the context you want, select Edit custom field config. The Script Master editor opens, titled with the field's name and ID, for example Comments count (customfield_10050), with the field type under it.

    Jira's field context page with the Edit custom field config link

Write and save the script​

  1. In Backend JavaScript, write the script. It must return a value of the field's type.

    The scripted field editor with Save, Version history and Snippets above the Backend JavaScript editor

  2. To start from an example, select Snippets and select one, for example Number: Comments count. Copy its code with the copy button, close the library, and paste the code into the editor.

  3. Optional: check the result on real work items with Preview on work items below the editor. See Preview a field on work items.

  4. Select Save, or press Ctrl+S (Cmd+S on a Mac).

Result: A Configuration saved message shows the new version number, for example v3. Jira uses the script the next time someone opens a work item that shows the field.

To describe the change for later, select the arrow next to Save, then Save with note…. The note can be up to 200 characters and appears in the version history.

Snippets for field scripts​

SnippetWhat it shows
Script Globals OverviewThe variables a field script can use
Get the current work item contextHow to read payload and log the work item and field IDs
Number: Comments countThe number of comments on the work item
String: Parent StatusThe status of the parent work item
User: Parent AssigneeThe assignee of the parent work item
DateTime: Last update of the parent work itemWhen the parent work item last changed

Go back to an earlier version​

Every save is a version. Select Version history to compare versions and restore one. See Version history.

Version history only records saves made in this editor. A change made another way, for example through the Jira REST API, isn't recorded.