Page tree

Versions Compared

Key

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

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
Status
colourGreen
titleCurrent
Version compatibility6.0.1 - Latest
SupportedYes
Introduced in version2.0.0


Condition

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.

Tip

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:

Info
iconfalse

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:

Info
iconfalse
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.




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

Image Added



Note

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:

Info
iconfalse
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.

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

Image Added