Validators Tutorial
Before you start this tutorial, make sure you've read the Workflow Functions Tutorial page to understand what workflow functions are, for an overview of ScriptRunner workflow functions, and for details on how to access workflow functions.
For this tutorial, we assume you already have basic knowledge of how Jira workflow functions work.
What is Great Adventure?
Great Adventure is the fictitious company we use to help provide use cases and examples of concepts covered. Great Adventure has the same problems and issues faced by most companies and needs to automate more of their processes using ScriptRunner.
Overview of ScriptRunner workflow validators
A validator checks to see if the user can transition an issue. Validators do not prevent the next transition button from appearing (that would be a condition). For example, you could add a ScriptRunner validator that ensures a user adds a comment when transitioning an issue to Done, or equivalent. Depending on what your organization requires, you may want to use workflow validators provided by ScriptRunner. These validators allow you to do more in your workflow, providing extra control or information. ScriptRunner includes built-in validators that you can use right away, but you can also create your own Simple scripted validator. For a full list of our validators, check out the available ScriptRunner workflow validators.
Navigate to ScriptRunner workflow validators
You can add a ScriptRunner validator to a workflow transition as follows:
Examples of ScriptRunner workflow validators
Below are some easy-to-follow examples that will help you understand how ScriptRunner workflow validators work.
Built-in ScriptRunner workflow validator examples
Field(s) required validator
User in field validator
Great Adventure wants to improve their approval process and make sure only those assigned as Approvers can approve an issue. To do this, Great Adventure plans to use the User in field(s) validator to make sure only users within the Approvers custom field can transition the issue to Approved.
You can now test to see if this workflow validator works. Issues in your chosen project will throw an error if you try to transition the issue to Approved and you're not the Approver.
Scripted ScriptRunner workflow validator example
Require Fix Version - Simple scripted validator
In addition, make sure the Fixed transition (from Awaiting Release to Fixed) includes a Resolve Issue screen that includes both the Resolution and Fix version.
In Great Adventure's Software Development team, they use Fix Versions to track when the team resolves bugs in the products. Similar to the Component issue, many users forget to add the Fix Version when completing the issue. Great Adventure has decided to use a script validator in their Software Development project, so when a user sets the resolution to Fixed, they also have to add the correct Fix Version.
You can now test to see if this workflow validator works:
- Transition an issue in your chosen project to Fixed.
- When the Resolve Issue screen pops up, enter the resolution of Fixed (or chosen equivalent).
- Leave the Fix version blank.
- Select the Fixed button (or chosen equivalent). You will get an error that stops you from transitioning unless the Fix version is provided.