Introduction

It's a validator that enables you to validate transitions by running your own Groovy Script.

You can use this validator to program your own custom logic if no predefined conditions suit your needs.

Element summary
Status
CURRENT
Version compatibility6.0.1 - Latest
SupportedYes
Introduced in version2.0.0

Validator parameters

You can choose between two methods of inputting your scripts.

  • Script template
  • Inline script

Script template - allows you to select a script from a drop-down list containing your collection of Reusable Validator Scripts.

Inline script - displays a field that allows you to input a new script from scratch. (Useful when you need to quickly add simple scripts you won't be using in other places.)

Validation

Validated transition is executed or cancelled based on logic contained in your Groovy Script.

In order to cancel a transition, validator needs to throw an exception. Otherwise, transition will be executed.

Even if Validator Script doesn't throw an exception, it's logic will still be executed. You can use this to perform various operations on transition stage.

Throwing an exception:

JIRA Transition Validators use InvalidInputException class to throw exception when transition needs to be cancelled. You need to import said class first in order for your script to work properly. This can be done by inserting the following line into your script:

import com.opensymphony.workflow.InvalidInputException;

Now that the class is imported, you have to make your code throw an exception. It's done by creating a new InvalidInputException object with following code:

throw new InvalidInputException("field-name", "Error message");

where "field-name" is the name of the field you want the message to appear under and "Error message" is the message text you want to appear.

Field names of all default Issue Fields can be found here. Custom Fields need to be indicated by their Custom Field ID.




This image shows a script that will display an error message under "Assignee" field if no user is assigned to the Issue.


Note that if the field you're throwing an exception for is not visible to the user, the error message won't be displayed at all. Though the transition will be cancelled.

You can also use another syntax:

throw new InvalidInputException("Error message");

By providing only one argument - "Error message" (without specifying field) an error will appear at the top of transition screen.

This method can be used to display general messages or when the field giving the error is not visible to the user.

Script shown on the image will display an error message at the top of screen instead of appearing under specific field.