Skip to main content
Skip table of contents

Working with ScriptRunner Behaviors

AVAILABLE SINCE 7.1.0

Checklist for Jira is compatible with ScriptRunner Behaviours API, which offers ways to manipulate the checklist data in real time while creating, transitioning or editing an issue.

In this section, we will explain which methods can be used.

Getting the checklist field

You can get the form field using the ScriptRunner Behaviours API. Once you have the form field, you can manipulate it in many ways.

GROOVY
def checklistField = getFieldByName("Definition of Done");
GROOVY
def checklistField = getFieldById("customfield_12345");

Interacting with checklist values

Because the ScriptRunner Behaviours API manipulates checklist fields in real time, manipulating checklist items in Behaviours, while be similar to what was described in the Getting started with ScriptRunner page, will have some differences is how values are obtained and updated.

Getting the checklist value

You can get the checklist value from the checklist field. The value is a String that contains a JSON array of checklist items.

GROOVY
String itemsAsJson = checklistField.getValue();

You can convert this String value into a collection of checklist items. Converting the items to Java objects will help further manipulations.

GROOVY
Collection<ChecklistItem> items = ChecklistSerializer.deserializeChecklist(itemsAsJson);

Updating the checklist Value

You can update the checklist field’s items in real time by setting the field’s value with a JSON array of checklist items.

If you were manipulating a collection of ChecklistItem Java objects, you can start by converting the collection to a String value.

GROOVY
String newItemsAsJson = ChecklistSerializer.serializeChecklist(items);

You can set the field’s value by calling the setValue method on the field.

GROOVY
checklistField.setValue(newItemsAsJson);

Changing the checklist field state

Making the field read-only

You can prevent users from editing the checklist. Making the field read-only this way bypasses the field’s permission scheme, if one is set, and prevents any user from editing or completing items.

GROOVY
checklistField.setReadOnly(true);

Making the field required

You can enforce there is at least one item in the checklist by making the field required.

GROOVY
checklistField.setRequired(true);

Examples

See the following pages for examples of what you can do with ScriptRunner Behaviours:

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.