Example Validators

The following examples can be used on all transitions.

Require One Linked Issue on Issue Creation

You have a support portal and a separate support development instance. You want to ensure that all issues created on the support development instance are linked to their corresponding user-facing ticket on the support portal. Ensure all issues created on one Jira instance are linked with their corresponding issue on another instance.

  1. Select the Create transition.

  2. Click Validators→Add Validator.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the validator in Name of ScriptRunner Script Validator for example, Require One Linked Issue.

  5. Insert the following ScriptRunner Script Validator:

    groovy
    issue.links.length >0

    This validator now ensures there must be at least one linked issue when an issue is created. If there are none, an error shows.

  6. Type an error message to show when the validator fails in Message to Show when Validation Fails.

    You can edit this script to make other fields required. For example replace links with fixVersions or components.

Select Lists Must be Populated

You want to enforce that issues have the required information before they are created. Specify that both select-list drop-downs in a custom cascading-select field must be populated to Create an issue.

  1. Select the Create transition.

  2. Click Validators→Add Validator.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the validator in Name of ScriptRunner Script Validator for example, Select Lists Must be Populated.

  5. Insert the following ScriptRunner Script Validator. Replace customfield_10093 in the example below with the ID of the cascading-select list field inside of your instance:

    groovy
    issue.customfield_10093.child.value.length >0
    To find the custom field ID navigate to <JiraBaseURL>/secure/admin/ViewCustomFields.jspa and Edit the required field. The field ID is shown.
  6. Type an error message to show when the validator fails in Message to Show when Validation Fails.
    This validator now ensures the custom field specified must have a value. If it is not, an error shows.

Sub-Tasks Must Be In Progress

As a project manager, you want to ensure all sub-tasks have been started before progress can start on the parent issue to keep issues aligned. Ensure all sub-tasks are In Progress before a parent issue can be transitioned to In Progress.

This example cannot be used on the Create transition.

  1. Select the Start Progress transition.

  2. Click Validators→Add Validator.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the validator in Name of ScriptRunner Script Validator for example, All Sub-tasks Must be In Progress.

  5. Insert the followingScriptRunner Script Validator:

    groovy
    issue.subtasks.filter(subtask => subtask.status.name == 'In Progress').length == issue.subtasks.length
  6. Type an error message to show when the validator fails in Message to Show when Validation Fails.
    This validator now ensures all sub-tasks of a parent issue are in the In Progress workflow step before the parent issue can be transitioned to In Progress.

Issue Description Length

As a support manager, you want to ensure that all bugs reported have detailed descriptions so you can replicate and solve as easily as possible. Enforce thorough descriptions on all issues before they can be created by setting a minimum character length.

  1. Select the Open transition.

  2. Click Validators→Add Validator.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the validator in Name of ScriptRunner Script Validator for example, Description Length.

  5. Insert the followingScriptRunner Script Validator. Changelength >30to specify the minimum required characters:

    groovy
    issue.description.plainText.length >30
  6. Type an error message to show when the validator fails in Message to Show when Validation Fails.
    This validator shows an error and blocks the creation of an issue if the Description field is under 30 characters.

Issue Must be in Current Sprint

As a project manager, you want to ensure that only issues planned in the current sprint are worked on. Allow work to be started only on issues that are in the current active sprint.

  1. Select the Start Progress transition.

  2. Click Validators→Add Validator.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the validator in Name of ScriptRunner Script Validator for example, Enforce Current Sprint.

  5. Insert the followingScriptRunner Script Validator:

    groovy
    issue.sprint.state == 'active'
  6. Type an error message to show when the validator fails in Message to Show when Validation Fails.
    This validator shows an error message when a user tries to transition an issue outside of the current active sprint.

Require Attachments

As a project manager, you want to ensure the required number of attachments have been added to an issue as it transitions, to align with business processes. Ensure a minimum number of attachments has been added as an issue transitions.

  1. Select the Create transition.

  2. Click Validators→Add Validator.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the validator in Name of ScriptRunner Script Validator for example, Require Attachments.

  5. Insert the following ScriptRunner Script Validator. Change length ==3 to specify the minimum required characters:

    groovy
    issue.attachments.filter(attachment => attachment.id == null).length ==3
  6. Type an error message to show when the validator fails in Message to Show when Validation Fails.
    This validator shows an error message when a user tries to transition an issue that doesn’t have the required number of attachments.

The transition screen must be configured with the Attachments field, to allow users to submit the attachments during the transition.