Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

You might want to remove some items from the checklist, but not all. This can be useful to filter out undesired unnecessary items in the a checklist.

Info

If you want to remove all items or reset the a checklist, see Update the a checklist with a new set of items instead.

To do so, retrieve the checklist from the issue and then remove items from the ArrayList:You start by retrieving the current list of Checklist Items.

Code Block
languagejava
def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField);

You then remove the targeted items from the collection.

Note

Notice the use of the .toList() in the loop, which avoids method to avoid concurrency exceptions (.i.e deleting an item while lopping on it)iterating over the collection. An iterator can also be used in place.

Code Block
languagejava
// 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

Finally, you update the custom field passing it the newly created collection.

Code Block
checklistCustomFieldType.updateValue(checklistCustomField, issue, existingChecklistValue);

...

The following example Following is a complete example that can be used to removes all items which has have the “Not Applicable” status:

...