Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

A workflow validator that is based on the result of

either a custom expression or a scripted Groovy expression.

If

 If the

Groovy

Related links:

Image Removed

When you add this validator to a transition and trigger the transition, the add-on checks the result of the groovy expression. If it returns false or a Groovy falsy, a validation error message is displayed.

Expected value

Click on the "Expected Value" tab in the Groovy editor help for a few examples on the expected value for the validator.

The value should be either:

  • A boolean value (true if validation passes or false if validation fails). For example, Fail the validation if the current user is not the reporter of the issue

    Code Block
    languagegroovy
    issue.reporter.name == currentUser.name
  • A String representing the error message to display (meaning that the validation fails). For example, Prevent the user from moving forward if the issue is unassigned

    Code Block
    languagegroovy
    if(!issue.get("assignee")){
      "You cannot move forward since the issue is unassigned"
    }

    If the issue is unassigned, then the message "You cannot move forward since the issue is unassigned" will be displayed. Note that you cannot include HTML in the error message because Jira escapes HTML in the error message.

  • Map<String,String> where each key is a field name or ID and the corresponding value is the error message to display for that field. For example, if the script returns:

    Code Block
    languagegroovy
    ["summary":"Too long","Description":"Too short"]

     then Too long will be displayed below the Summary field, and Too short will be displayed below the Description field. Note that the field can be identified either by its name or its ID.

  • or else, any value that will be interpreted as either "truthy" (validation passes) or "falsy" (validation fails)

    Code Block
    languagegroovy
    issue.resolution

    this returns the Resolution object which is considered truthy.

Examples of custom validators

With simple Groovy scripting, you can create custom validators that fit your purpose using this Validator. 

For example, if you want to prevent the user from resolving an issue if the issue has an unreleased Fix Version/s either from before or added during the transition:

Code Block
!issue.fixVersions.any{it.isReleased()}

In this validator, you can access the values modified during the transition using the getModifiedFields() method of the Issue interface. For example, if you want to check during a transition that the issue is assigned to a specific user:

Code Block
issue.modifiedFields?.get("assignee")?.getNewValue() == currentUser

In this validator, you can access the issue fields before and during/after the transition using the originalIssue and issue variables respectively. For example, during a Story modification, you want to check that the Story points of the Story have not been raised by more than 5:

Code Block
issue.get("Story Points") - originalIssue.get("Story Points") < 6
Look here for more use cases for this validator.

expression returns false (or falsey), a validation error message will be displayed.

To add 'Scripted (Groovy) Validator' to a transition:

  1. Click Edit for the workflow that has the transition you wish to configure the validator on.

  2. In the Workflow Designer, select the transition.

  3. Click on Validators in the properties panel.

  4. Click on Add validator.

  5. Select Scripted (Groovy) Validator from the list of validators.

  6. Click on Add to add the validator.

  7. Write a Groovy expression in the Groovy script field.

  8. Input a message in the Error message field.

  9. Select on which field the error message should be displayed.

  10. Click on Add to add the validator to the transition.

Note

On the Service Management portal view of a request, the customer will not see the Error message when the validator fails. This is due to a known limitation (JSDSERVER-5822) with Atlassian. However, you can still customize the Error message using this workaround.

The Build-your-own validator will evaluate when its Transition is triggered and will either allow the transition or display an error message, based on the outcome of the included expression - when the expression evaluates to true (or “truthy” in the case of Groovy expressions) the transition will proceed; otherwise the transition will not be triggered and a message will be displayed to the user. There are two options for creating an expression:

  • No Code - Build an expression to test the value of a field using standard operators (e.g. “equals/does not equal”, “greater than/less than”, and “is empty/is not empty” among others). Field values can be compared to other fields or to static values.

  • Groovy Script - For even greater flexibility, build a Groovy expression that evaluates to true or false (or truthy/falsey). For more information on using Groovy in JMWE, see Using Groovy with JMWE.

Note: the No Code option for this Validator enables you to build an expression using several fields to configure which field should be evaluated, and the conditions that the field value must meet in order to evaluate to true or false. Once the No Code fields have been configured, a Groovy script will be generated for you! The Validator can be saved as configured, and it will remain a No Code validator or it can be switched to a Groovy script validator that automatically uses the generated script.

Alternately, the generated Groovy script can be copied so it can be updated and/or customized outside of JMWE.

Include Page
[Includes] Adding a Validator
[Includes] Adding a Validator

Configure the validator

  1. Follow the steps above to add a validator to a Transition.

  2. From the list of validators, select Build-your-own Validator.

  3. Click Add.

  4. The Build-your-own Validator page will open (Figure 1, right). Configure the validator as needed. See below for details on each of the configurations.

  5. Click Add.

Options

The following options are available:

  • Description - Give the validator a description. The Description will be displayed in the list of validators for a Transition.

  • Error message - The error message that will display to the user when the validator evaluates to false.

  • Choose Type - Select either No Code to build a validator using standard logical operators, or select Groovy Script to enter a Groovy expression.

  • Field - Only available when Choose Type, above, is set to No Code. Select the field to be evaluated.

  • Operator - Only available when Choose Type, above, is set to No Code. Select the logical operator to use in the field evaluation.

  • Value to compare type - Only available when Choose Type, above, is set to No Code. Configure whether to compare the field value to another field or to a static value.

  • Value to compare - Only available when Choose Type, above, is set to No Code. This field updates based on the setting for Value to compare type:

    • Field - When value to compare type is set to ‘Field’, this field is a pulldown menu used to select the comparing field to use in evaluation.

    • Text - When value to compare type is set to ‘Text’, this field is a text field where a static value can be entered.

  • Regex - Only available when Choose Type, above, is set to No Code and Operator is set to Matches a regular expression/Does not match a regular expression. The regular expression to use in the field evaluation.

  • Compiled script - Only available when Choose Type, above, is set to No Code. After all other fields have been configured, the compiled script will be displayed (Figure 2, right). The Compiled script window includes two buttons:

    • Test ( (blue star) ) - Test the compiled script against an existing issue to determine the outcome.

    • Copy ( (blue star) ) - Copy the compiled script to the clipboard.

  • Groovy script - Only available when Choose Type, above, is set to Groovy script.

Info

You are viewing the documentation for Jira Data Center/Server.

On This Page

Table of Contents
minLevel1
maxLevel2
outlinefalse
typelist
printablefalse
Image AddedImage Added