Versions Compared

Key

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

The following example updates the checklist with a completely new list of items:

Code Block
languagejava
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);