Custom Validators

Modify or create a new workflow.

Add a new validator.

Most of the built-in workflow functions can be customized with Condition code or Additional actions code, so if you can use a built-in script, you should.


Example 1. Where to put your scripts?

Give either the absolute path of the script, or path relative to one of your script roots. Relative paths are more portable and make switching servers easier.

If your scripts/classes have a package declaration, obviously, you will need the correct directories under there.

Simple built-in scripts like Simple Scripted Validator can be used to avoid most of the boilerplate in writing a validator function.

Script Binding

For each type of workflow function, the plugin will provide the current issue and transientVars in the script binding. That means you can refer to them using these variables, without declaring them.

log.debug issue.getKey()

If you use Intellij IDEA, you can add a dynamic property for these variables of the correct type. Alternatively you can just redeclare it with type information:

groovy
import com.atlassian.jira.issue.Issue; Issue issue = issue

Validators

To disallow the transition you throw a new InvalidInputException (com.opensymphony.workflow.InvalidInputException).

This has constructors for specifying a general error message, and for applying an error message to a particular field. For example, to set the resolution field in error:

import com.opensymphony.workflow.InvalidInputException

throw new InvalidInputException("resolution", "Resolution must not be fixed if not specifying a fix-version")
Copy

To apply a general error message:

throw new InvalidInputException("Some combination of multiple fields are in error")
Copy

Instead of a custom validator you may prefer to use Simple Scripted Validator, which has a UI where you specify what field to apply the error message to.

On this page