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

It is a common use-case to reset the checklist completely and build it from the ground up. This page will demonstrate how to achieve it.


To assign a new set of items, you must create a new ArrayList<ChecklistItem>:

// Create a new Checklist
def ArrayList<ChecklistItem> newChecklistValue = new ArrayList<ChecklistItem>();
def item = checklistCustomFieldType.getSingularObjectFromString('{"name": "item name"}');
newChecklistValue.add(item);

// Update the issue with the new checklist
checklistCustomFieldType.updateValue(checklistCustomField, event.issue, newChecklistValue);

Here is a complete example that updates the checklist with a new set of items:

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.*;

def ChecklistItem createChecklistItem(ChecklistCFType cfType, String name, boolean checked, String status, boolean mandatory, int rank) {
    def itemJson =  """
    {
        "name": "${name}",
        "checked": ${checked ? "true" : "false"},
        "statusId": "${status == null || status == "" ? "none" : status}",
        "mandatory": ${mandatory ? "true" : "false"},
        "rank": ${rank}
    }
    """;
    return cfType.getSingularObjectFromString(itemJson);
}

// 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();

// Create a new Checklist
def ArrayList<ChecklistItem> newChecklistValue = new ArrayList<ChecklistItem>();
newChecklistValue.add( createChecklistItem(checklistCustomFieldType, "Compile the solution", false, null, true, 0) );
newChecklistValue.add( createChecklistItem(checklistCustomFieldType, "Run all tests", true, "notApplicable", false, 1) );

// Update the issue with the new checklist
def issue = (MutableIssue) event.issue;
checklistCustomFieldType.updateValue(checklistCustomField, issue, newChecklistValue);
  • No labels