This documentation is for version 4.x. For the latest documentation, click here
Remove items from a checklist
You might want to remove some items from the checklist, but not all. This can be useful to filter out unnecessary items in a checklist.
If you want to remove all items or reset a checklist, see Update a checklist with a new set of items instead.
You start by retrieving the current list of Checklist Items.
def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField);
You then remove the targeted items from the collection.
Notice the use of the .toList()
method to avoid concurrency exceptions .i.e deleting an item while iterating over the collection. An iterator can also be used in place.
for (ChecklistItem item : existingChecklistValue.toList()) {
if (item.getName() != "Only Accepted Item Name") {
existingChecklistValue.remove(item);
}
}
Finally, you update the custom field passing it the newly created collection.
checklistCustomFieldType.updateValue(checklistCustomField, issue, existingChecklistValue);
Following is a complete example that can be used to removes all items which have the “Not Applicable” status: