Skip to end of banner
Go to start of banner

Scripted Field

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

Scripted Fields are currently in limited release. Full availability of Scripted Fields will occur in a future release.

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

There are two paths for adding a JMCF custom field - through the My Custom Fields page or through the native Jira Custom fields page.

To create a new field through My custom fields:

  1. Log into your Jira instance as an Administrator.

  2. Click Settings ⚙️ in the upper right corner.

  3. Select Apps.

  4. In the left-hand panel, click Jira Misc Custom Fields.

  5. Select My custom fields.

  6. Click New custom field in the upper right corner.

  7. Give the custom field a name and, optionally, a description. Note: the maximum length of both the name and description fields is 255 characters.

  8. Select the JMCF field type and click Next.

  9. Follow the steps in the next section to configure your custom field.

To create a new JMCF custom field through the Jira custom fields page:

  1. Log into your Jira instance as an Administrator.

  2. Click Settings ⚙️ in the upper right corner.

  3. Select Issues.

  4. In the left-hand panel, click Custom fields.

  5. Click Create custom field in the upper right corner.

  6. In the Select a Field Type window, click Advanced.

  7. Select the JMCF field type you want to add and click Next.

  8. Give the custom field a name and, optionally, a description.

  9. Click Create.

  10. Follow the steps in the next section to configure your custom field.

Note: If you create a JMCF custom field using the native Jira custom field process, the new custom field will not calculate until its Contexts have been updated; this limitation applies even when the custom field is configured for the Default context.

Edit a custom field

There are two ways you can access a custom field to edit its configuration after it has been created:

  1. From the My custom fields page of JMCF Administration, click Action (blue star) and select Edit. Update the name and description, add or remove screens, and update the JMCF configurations described above.

  2. From the Jira Custom fields administration page, click Action (blue star) and select an option:

    1. Edit details - Update the Field Name, Description, and Search Template for the field.

    2. Contexts and default value - Add or remove contexts for the field. Additionally, configure the Default Value and access the Custom field config to set the JMCF configurations described above.

    3. Translation and options - Set the language in Choose Language, then enter the Field Name and Description for that language.

    4. Associate to Screens - Add or remove Jira screens on which the field will appear.

    5. Move to Trash - Remove the custom field from all screens and move it to the Trash.

Custom fields can be recovered from the Trash for 60 days. After 60 days, the field will be deleted permanently and cannot be recovered!

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.
      (warning) 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

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:

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

  • (blue star) Templates - Pre-written script examples.

  • (blue star) 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.

Note: automatic recalculation of scripted fields using dependencies requires that Jira triggers a system event when the dependency is updated. This is generally true, but may not work with all fields.

customField-ScriptedEditor.png

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)

Much like testing other JavaScript, using the console can greatly assist in testing. However, instead of needing to use the browser’s console, you can use the Console output window. Anywhere you include console.log() in the custom field script, the results of that command will be added to the Console output window. Adding logs to the console is an effective way of testing intermediate values and troubleshooting script components.

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

Currently, there are no specific search templates for custom fields created with JMCF; currently the only search template available is Forge custom field searcher, the default search template for Jira Forge apps. Because JMCF uses native data types, the fields are generally searchable using JQL and basic search. However, there are some limitations:

  • Time in Status can only be searched by number of seconds.

Search template flexibility will be expanded in later versions of JMCF for Jira Cloud as the Forge team introduces more capabilities for search.

customField-ScriptedTestResults.png

  • No labels