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

Version 1 Next »

The following example will add items to an existing checklist:

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

// Add items to the existing Checklist
def issue = (MutableIssue) event.issue;
def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField);
def maxRank = existingChecklistValue.size();
existingChecklistValue.add( createChecklistItem(checklistCustomFieldType, "Move the folder structure", false, null, true, maxRank++) );
existingChecklistValue.add( createChecklistItem(checklistCustomFieldType, "Remove *.exe files", false, null, true, maxRank++) );

// Update the issue with the checklist
checklistCustomFieldType.updateValue(checklistCustomField, issue, existingChecklistValue);
  • No labels