Deleting items from checklists using SIL
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 Updating checklists with new sets of items using SIL instead.
Steps
Retrieve the current list of checklist items converted from JSON to the
oChecklistItem
structure.CODEoChecklistItem[] items = fromJson(DoD);
Remove the targeted items from the collection.
CODEfor(oChecklistItem item in items) { // We only keep items that are named "Code reviewed" or are checked if (item.name != "Code reviewed" && !item.checked) { items -= item; } }
Update the custom field by passing it the newly created collection converted to JSON.
CODEDoD = toJson(items);
Example
Here is a full example that can be used to remove all items with the “Not Applicable” status:
// Retrieve the items in a Structure array to facilitate manipulations
oChecklistItem[] items = fromJson(DoD);
for(oChecklistItem item in items) {
// Remove all items whose status is "Not Applicable"
if (item.statusId == "notApplicable") {
items -= item;
}
}
// Update the checklist with its new values
DoD = toJson(items);