Validating user input in workflow transitions

For workflow transitions that have transition screens, you can add validation logic to make sure what the users put in is what you are expecting. This is a great way to ensure data integrity, and we can do this with workflow validators.

In this recipe, we will add a validator to perform a date comparison between a custom field and the issue's create date, so the date value we select for the custom field must be after the issue's create date.

Getting ready

For this recipe, we need to have the JIRA Suite Utilities add-on installed. You can download it from the following link, or install it directly using the Universal Plugin Manager:

https://marketplace.atlassian.com/plugins/com.googlecode.jira-suite-utilities

Since we are also doing a date comparison, we need to create a new date custom field called Start Date and add it to the Workflow Screen.

How to do it...

Perform the following steps to add validation rules during a workflow transition:

  1. Select and edit the workflow to configure.
  2. Select the Diagram mode.
  3. Select the Start Progress transition, and click on the Validators link on the right-hand side.
  4. Click on the Add validator link, and select Date Compare from the list.
  5. Configure the validator with the following parameters:
    • The Start Date custom field for This date
    • The Greater than sign > for Condition
    • Created for Compare with
  6. Click on Add to add the validator:
    How to do it...
  7. Click on Publish Draft to apply the change.

After adding the validator, if we now try to select a date that is before the issue's create date, JIRA will prompt you with an error message and stop the transition from going through, as shown in the following screenshot:

How to do it...

How it works...

Validators are run before the workflow transition is executed. This way, validators can intercept and prevent a transition from going through if one or more of the validation logics fail.

Note

If you have more than one validator, all of them must pass for the transition to go through.

See also

Validators can be used to make a field required only during workflow transitions. Refer to the Making a field required during workflow transition recipe for more details.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset