This documentation is for version 4.x. For the latest documentation, click here

Validate a Checklist

Checklist for Jira already offers a highly versatile Validator but sometimes you require more complex validations. This is where a custom scripted validator comes into play.

The following scripts are using a ScriptRunner Script Validator.

To validate a Checklist, you first retrieve the collection of checklist items from the issue.

def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField);

Then you extract and validate the desired information from the item

// Find out if all items have statuses def allItemsHaveStatuses = existingChecklistValue.size() > 0; for (ChecklistItem item : existingChecklistValue) { if (!item.hasStatus()) { allItemsHaveStatuses = false; break; } }

Finally, you throw an exception if the validation failed.

// Throw exception if not all items have statuses if (!allItemsHaveStatuses) { throw new InvalidInputException("All items must have statuses in '" + checklistCustomField.getName() + "' Checklist."); }

Following is a complete example of a Custom Validator that verifies if at least one item is checked.