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 2 Next »

The following example removes all items with the “N/A” status:

Notice the .toList() in the loop, which avoids concurrency exceptions (deleting an item while lopping on it). An iterator can also be used.

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