Removing items from checklists using ScriptRunner
You may want to remove some items from a checklist, but not all of them. This can be useful to filter out unnecessary items in a checklist.
To remove all items or reset a checklist, see Replace all items in a checklist using ScriptRunner instead.
Steps
Get the custom field, custom field type and items of your Checklist field.
def customFieldManager = ComponentAccessor.getCustomFieldManager(); // Remplace the custom field ID with whatever ID your custom field has def checklistField = customFieldManager.getCustomFieldObject("customfield_10101"); def checklistCFType = (ChecklistCFType) checklistField.getCustomFieldType(); Collection<ChecklistItem> items = (Collection<ChecklistItem>) checklistCFType.getValueFromIssue(checklistField, issue);
Loop through your items and remove the items you wanted removed.
// The "toList()" here is important. If not specified, the script will fail with a ConcurrentModificationException for (ChecklistItem item : items.toList()) { if (item.getName() != "Only Accepted Item Name") { items.remove(item); } }
Update the issue with the updated item list.
checklistCFType.updateValue(checklistField, issue, items);
Full example
Here is a full example where items are removed from a Checklist field.