Scripted Field

The Scripted custom field types are a set of calculated fields that utilize JavaScript to calculate a return value, usually based on other field values. They are read-only fields.

Within JMCF for Jira Cloud, there are several types of scripted fields, each corresponding to the type of value the script returns (the script must return the data type of the field).

Note: if a scripted field encounters and error during calculation or recalculation, the calculation of that field will pause. Other custom fields in your instance will continue to (re)calculate.

Errors with a scripted field will be displayed in the Error Logs page; errors will not be indicated on issue screens. The only indication of an error in a field recalculation will be:

  • If the field is new and has never been calculated, the value will remain None.

  • If the field’s script returns a value of undefined, the value will display None.

  • If the error occurred during recalculation, the field value will fail to update.

Field types

The following scripted field types are currently available:

  • Scripted string - Returns a string value.

  • Scripted datetime - Returns a datetime value.

  • Scripted number - Returns a number value.

  • Scripted user - Returns an Atlassian account ID or a user object.

  • Scripted group - Returns a group ID or a Group object.

  • Scripted string collection - Returns a collection of string values.

  • Scripted user collection - Returns a collection of user IDs or user objects.

  • Scripted group collection - Returns a collection of Group IDs or Group objects.

Add a custom field

Edit a custom field

Configure a new ‘Scripted’ field

If you added a JMCF custom field through the native Jira custom fields screen, see Edit a custom field, below.

Follow the steps above to add a custom field to your Jira instance, then follow these steps:

  1. In the Associate Screens step of the wizard, check the boxes for the screens to which the field should be added.

    1. Use the search field above the list of screens to locate a specific screen.

    2. Check the box at the top of the column to add the field to all listed screens.
      Note: some team management screens in Jira do not currently support custom fields!

  2. Click Next.

  3. The Configure Field screen will open; from here you can enter the script for the field, configure its dependencies, and test it before saving. See Script Configuration, below, for more information.

  4. Click Save.

You are viewing the documentation for Jira Cloud.

On This Page

customField-Scripted.png
Figure 1 - Scripted string field

 

Script configuration

JMCF Scripted fields use JavaScript to calculate an output. The output of your script must match the field type you selected when creating the custom field (e.g. a string or a user object); see Field Types, above, for a list of all supported output types.

When a new custom field is first configured, the script editor (Figure 2, right) will be populated by an example script; replace this with your own script. The script editor window includes standard code editing features, including syntax colorization, error highlighting, code formatting, and code completion.

The editor also includes three shortcut buttons to the right side of the window:

  • Expand/Contract - Expand the editor to full height, or shrink it back to its original height.

  • Templates - Pre-written script examples.

  • Help - Links to JMCF for Jira Cloud documentation, scripted field documentation, and the Appfire support portal.

API access

JMCF Scripted fields have access to a limited set of data through the Jira API. Currently, access is limited to the current issue’s fields including:

  • All issue fields - api.issue.getField

  • Users - api.jira.getUser

  • Groups - api.jira.getGroup and api.jira.getGroupUsers

  • Projects - api.jira.getProject

Dependencies

In addition to writing your script, you can also create dependencies between your scripted field and other fields using Dependencies on other fields. When you create a dependency, your scripted field will recalculate whenever the configured fields change. This includes standard issue fields and special fields such as Attachments, Comments, Issue Links, and Worklogs.

Dependent fields do not need to be referenced within the script, but if it is added as a dependency but not included in your scripted field, your custom field may recalculate more than necessary. Additionally, if a field is included in your script but is not added to the list of dependencies, the scripted field will not recalculate automatically and it may take additional time for recalculation as the updated field values will not be prefetched.

customField-ScriptedEditor.png
Figure 2 - Script editor

 

Testing your script

The testing features built into Scripted field configuration can greatly assist in building your script and verifying its output before you save it. You can test your script against a specific issue and JMCF will:

  • Verify that the script output type matches the return type for the custom field (Point 1, Figure 3, right)

  • Indicate whether the script executed successfully or encountered an error (Point 1, Figure 3, right)

  • Display the outcome of the script (Point 2, Figure 3, right)

  • Display the contents of the console (if any) (Point 3, Figure 3, right)

To test your script:

  1. Enter the ID of the issue against which your script should be run (e.g. ‘TEST-19’). Note: currently, searching by Jira ID is not supported.

  2. Click Test.

  3. The result of your script will be displayed below the issue selection (Figure 3, right):

    1. If your script runs successfully, a SUCCESS badge will show, and the results of the script and any console logs will be displayed.

    2. If your script encounters any issues, ERROR will be displayed and the Test result window will show the specific error message, and any console logs will be shows up to the point of the error.

Search templates