The Checklist custom field can be programmatically manipulated to extract and modify it’s data. You can use any scripting tool that allows you to access the custom field’s Java based classes but one of the most popular tool for doing this is ScriptRunner which uses groovy scripts.
...
While many operations can be directly performed directly on the custom field, such as extracting and updating the checklist data, some manipulations will require access to the custom field type.
...
Method Name | Return Value / Description |
---|---|
getId | Long. Unique identifier for the item (returns the Option ID if an Option). |
isChecked | Boolean. Indicates if the item is checked. |
getName | String. Item name. |
getRank | Integer. Indicates the order of the item. |
isMandatory | Boolean. Indicates if the item is mandatory. |
getStatusId | String. Identifier for the item’s status (none if no status selected). |
hasStatus | Boolean. Indicates if a status is present. |
getOptionId | Long. Returns the ID of the Option (If applicable, otherwise returns -1). |
isOption | Boolean. Indicates if this item is an option (global item). |
isDisabled | Boolean. Indicates if the linked option is disabled. |
toJson | String. Returns JSON representation of the item. |
setRank(Integer rank) | Void. Changes the rank of the item. |
setStatusId(String statusId) | Void. Changes the status ID of the item. |
setDiscretionary(Boolean discretionary) | Void. Changes the discretionary (not mandatory) state of the item. Setting false means mandatory. |
setChecked(Boolean checked) | Void. Changes the checked state of the item. |
...
It is important to note that this Json structure slightly differs from the Json structure of the Modifying Checklists using a REST API article. Use the following structure when creating a new ChecklistItem
.:
Json Property | Type / Description |
---|---|
id | Number. Unique identifier. When creating items, this This can be ignored when creating items. |
optionId | Number. Option Identifier. You only need to provide the Option ID if you want to modify an option. |
name | String. Name of the item. This is the only mandatory property in order to create a ChecklistItem. |
checked | Boolean. Indicates if the item is checked. |
mandatory | Boolean. Indicates if the item is mandatory. |
rank | Number. Indicates the order of the item. |
statusId | String. Indicates the status identifier of the item. “none” means no status. |
...
Code Block |
---|
import com.atlassian.jira.component.ComponentAccessor;
// Retrieve the Custom Field Type for the Checklist Custom Field
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def checklistCustomField = customFieldManager.getCustomFieldObject("customfield_10013");
def checklistCustomFieldType = (ChecklistCFType) checklistCustomField.getCustomFieldType();
// Get the Checklist value
def issue = event.issue;
def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField); |
...