Calculated (Scripted) Labels custom field type

 

Add a Calculated (scripted) Labels custom field type

To add a Calculated (scripted) Label custom field type to your instance:

  1. Log in to Jira as an administrator.

  2. Click the Administration icon on the top right corner of the page.

  3. Click Issues - > Custom fields.

  4. Click Add custom field. The Select field type dialog is displayed where you can add a custom field type.

  5. Click Advanced in the left panel.

  6. Locate Calculated (scripted) Labels Field (JMCF app) and select it.

  7. Click Next. You are navigated to the Configure 'Calculated (scripted) Labels Field (JMCF app)' field dialog.

  8. Provide a name for the custom field.

  9. You can optionally provide a description of the custom field.

  10. Click Next. You are navigated to the Configure context dialog.

  11. Configure the following:

    • Select issue types: Select the issue types for which the custom field is enabled.

    • Choose context: Select one of the following:
      Apply to issues in selected projects (Recommended option): Creates a custom field only in issues that belong to projects specified in Select projects. This option has a low impact on the indexing time.
      Apply to all issues on your instance: Creates a custom field for all the issues on your Jira instance. This option has a great impact on the indexing time.

  12. Click Create to create the custom field.

  13. Click ellipsis under the Action column of the custom field and select:

    • Screens to associate the custom field to appropriate screens.

    • Configure to create a formula (explained in Configuration details) for the custom field.
      You can create multiple contexts if you need to associate different formulas with particular projects or issue types.

  14. Perform a re-index as prompted by JIRA.

Configuration details

Configure the Groovy formula for a Calculated (scripted) Labels custom field type

To write a formula for the Calculated (scripted) Label custom field type;

  1. Locate the custom field on the Custom Fields administration page.

  2. Click the ellipsis under the Action column of the respective custom field and select Configure to create a formula for the field.

  3. Click Edit Groovy Formula.

  4. In the editor write a Groovy script that returns a String representing a single/multi-line text. Also, you can test your script against any issue using the Groovy script tester.

  5. Click Save.

As documented on the Expected Value tab of the Groovy help editor, the Groovy formula must return one of the following values:

  • A space-separated list of labels.  "label1 label2"

  • An array of labels: ["label1", "label2"]

  • A Set of Label objects

Examples:

  • A space-separated list of labels:

    1 "Marketing Sales"
  • Labels of the current issue:

    1 issue.get("labels")
  • Label value based on the reporter:

    1 issue.get("Reporter").username == 'msmith' ? "QA" : "DEV"

Customize the search template

When creating a Calculated (scripted) Label custom field type, you can configure the Search template as Labels Searcher (Statistics-compatible). This is a custom statistics-compatible searcher provided by JMCF that searches for values matching labels. If you select “None” for the searcher, you won’t see any reference to this field in the Issue Navigator search fields. 

Note that changing a custom field searcher requires a re-index.

Customize the display of the Calculated (scripted) Label custom field type value on the issue detail view

You can define a velocity template that will return the HTML representation of the calculated custom field on the issue detail view, in addition to the formatting provided in the custom field value. Leave it empty to use the default template. 

To select a format for a Calculated (scripted) Label custom field type value;

  1. Locate the custom field on the Custom Fields administration page.

  2. Click the ellipsis under the Action column of the respective custom field and select Configure to create a formula for the field.

  3. Click Edit Velocity Template.

  4. Input the template.

  5. Click Save.

You can use the following Velocity variables in the template:

  • $value: the raw field value a String

  • $formattedValue: a String

  • and other variables described on this page

For example:

1 2 3 <font color="red"> $value </font>

Customize the display of the Calculated (scripted) Label custom field type value on the search list view

You can define a velocity template that will return the HTML representation of the calculated custom field on the search list view, in addition to the formatting provided in the custom field value. Leave it empty to use the default template. 

To select a format for a Calculated (scripted) Label custom field type value;

  1. Locate the custom field on the Custom Fields administration page.

  2. Click the ellipsis under the Action column of the respective custom field and select Configure to create a formula for the field..

  3. Click Edit List View Velocity Template.

  4. Input the template.

  5. Click Save.

You can use the following Velocity variables in the template:

  • $value: the raw field value a String

  • $formattedValue: a String

  • and other variables described on this page

For example:

1 2 3 <font color="red"> $value </font>

Display the Calculated (scripted) Label custom field type on Transition and Edit screen

The Never show on Transition and Edit screens option controls whether the Calculated (scripted) Label custom field can appear on transition and edit screens. If you select this option, the field will not be visible on any Edit or Transition screen, even if it is added to the screen.