This documentation is for version 4.x. For the latest documentation, click here

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

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:

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);
  • No labels