You might want to remove some items from the checklist, but not all. This can be useful to filter out undesired items in the checklist.
If you want to remove all items or reset the checklist, see Update the checklist with a new set of items instead.
To do so, retrieve the checklist from the issue and then remove items from the ArrayList:
Notice the .toList()
in the loop, which avoids concurrency exceptions (deleting an item while lopping on it). An iterator can also be used.
// Filter items, only "Only Accepted Item Name" can be part of the Checklist def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField); for (ChecklistItem item : existingChecklistValue.toList()) { if (item.getName() != "Only Accepted Item Name") { existingChecklistValue.remove(item); } } // Update the issue with the filtered checklist checklistCustomFieldType.updateValue(checklistCustomField, issue, existingChecklistValue);
The following example removes all items which has the “Not Applicable” status:
import com.onresolve.scriptrunner.runner.customisers.WithPlugin; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.MutableIssue; @WithPlugin("com.okapya.jira.checklist") import com.okapya.jira.customfields.*; // 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(); // Remove N/A items from the Checklist def issue = (MutableIssue) event.issue; def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField); for (ChecklistItem item : existingChecklistValue.toList()) { // Remove all items with "Not Applicable" status if (item.getStatusId() == "notApplicable") { existingChecklistValue.remove(item); } } // Update the issue with the checklist checklistCustomFieldType.updateValue(checklistCustomField, issue, existingChecklistValue);