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

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Checklist for Jira already offers a quite versatile Validator, but sometimes you need a more specific validation. This is where a custom scripted validator comes in play.

The following scripts are using a ScriptRunner Script Validator.


To validate a Checklist, retrieve the value from the issue, calculate the desired information from the list, then throw an exception if the validation should not pass.

// Retrieve checklist items
def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField);

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

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

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

import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
@WithPlugin("com.okapya.jira.checklist")
import com.okapya.jira.customfields.*;
import com.atlassian.jira.component.ComponentAccessor;
import com.opensymphony.workflow.InvalidInputException;

// Retrieve the Custom Field Type for the Checklist Custom Field
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def checklistCustomField = customFieldManager.getCustomFieldObject("customfield_10000");
def checklistCustomFieldType = (ChecklistCFType) checklistCustomField.getCustomFieldType();

// Retrieve Checklist items
def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField);

// Find out if any item is checked
def anyItemChecked = false;
for (ChecklistItem item : existingChecklistValue) {
    if (item.isChecked()) {
      anyItemChecked = true;
      break;
    }
}

if (!anyItemChecked) {
    throw new InvalidInputException("At least one item must be checked in '" + checklistCustomField.getName() + "' Checklist.");
}
  • No labels