Field Behaviours

Use Field behaviours to control how fields appear and function in specific spaces or work item types. You can use field behaviours to:

  • Set a field value based on another field
  • Change the name or description that is displayed for a field
  • Show or hide fields for people in a specific role

Execution history

Saved field behaviours keep a full execution history, so you can review when they were run, and what the output was, making it easier to audit and troubleshoot.

When a script runs, the execution history shows:

  • Anything logged with console.log(...)
  • The final value returned by your script with return

Use console.log(...) for messages, intermediate values, or debugging, and include a return statement for the main result you want to display. 

The difference between Jira and JSM field behaviours

Jira field behaviours run directly on Jira work item screens. You can apply them to multiple view types, including:

  • Create – when a user creates a work item
  • Transition – when a user moves a work item through a workflow transition
  • View – when a user views an existing work item

This allows you to control and react to fields throughout the work item lifecycle within Jira.

JSM field behaviours apply only to Jira Service Management request forms, and only on the Create view. They control how fields behave when a customer raises a request, but they do not run on transition or view screens.

Create a field behaviour

Follow these steps to create a new field behaviour:

  1. In Jira administration, select Marketplace apps.
  2. Under Apps, select ScriptRunner.js.
  3. Select Field behaviours.
  4. Select Create.
  5. Enter a Name and, optionally, a Description.
  6. Select Add mappings to configure where your behaviour applies to:
  7. Select the field behaviour Type to choose whether it applies to Jira or Jira Service Management (JSM).
    1. Choose the Space(s) you want this field behaviour to apply to. 
    2. Choose the Work types you want this field behaviour to apply to.

      Work type selection

      If you select more than one space, work types that are shared between those spaces are shown separately at first (for example, Space 1 – Task and Space 2 – Task). When you select one of these shared work types, the other copies of the same work type are removed from the list.

      For example, if you chose Space 1 and Space 2, you will initially see both Space 1 – Task and Space 2 – Task. After you select one of the Task entries, the other Task option is hidden.

    3. Choose the View types (Create, Transition, View) you want this field behaviour to apply to.

      JSM and View types

      If you selected Jira Service Management (JSM) as the field behaviour Type, the View types option does not appear. JSM field behaviours are only available on the Create view.

  8. Write your script.

    To help you write scripts, you can use the field behaviour examples, use HAPI, or select Example scripts directly in the script editor.

  9. Select Save

Edit a field behaviour

Use these steps to modify an existing field behaviour:

  1. In Jira administration, select Marketplace apps.
  2. Under Apps, select ScriptRunner.js.
  3. Select Field behaviours.
  4. Find your field behaviour in the list and select Edit.
  5. Modify the field behaviour as needed.
  6. Select Save

Enable and disable a field behaviour

To enable or disable your field behaviour:

  1. In Jira administration, select Marketplace apps.
  2. Under Apps, select ScriptRunner.js.
  3. In ScriptRunner, select Field behaviours.
  4. Locate the field behaviour you want to enable or disable.
  5. Open the ellipsis (…) menu for that field behaviour and select Disable or Enable.

Delete a field behaviour

Remove field behaviours you no longer need to keep your list organized and reduce clutter. When you delete a field behaviour, it’s removed from your active field behaviours list and will no longer run, but it isn’t permanently removed. You can still access and restore it from ScriptRunner if needed.

To delete a field behaviour:

  1. In Jira administration, select Marketplace apps.

  2. Under Apps, select ScriptRunner.js.

  3. Select Field behaviours.

  4. Find the field behaviour you want to remove.

  5. Open the ellipsis (…) menu for that field behaviour.

  6. Select Delete.

  7. When prompted, confirm that you want to delete the field behaviour.

    Deleted field behaviours can be restored, including their execution history.

Restore a deleted field behaviour

You can restore deleted field behaviours along with their execution history. To restore a deleted field behaviour:

  1. In Jira administration, select Marketplace apps.
  2. Under Apps, select ScriptRunner.js.
  3. Select Field behaviours.
  4. Use the filter and select Deleted to view deleted field behaviours.
  5. Find the field behaviour you want to restore.
  6. Open the ellipsis (…) menu for that field behaviour.
  7. Select Restore. The field behaviour and its full execution history will be available again in your active Field behaviours list.
On this page