The best way to create a new Checklist Item object is to use the getSingularObjectFromString(String)
method of the Custom Field Type.
Retrieve the Custom Field Type and use a JSON representation string to generate a new ChecklistItem
.
import com.atlassian.jira.component.ComponentAccessor; // Retrieve the Custom Field Type for the Checklist Custom Field def customFieldManager = ComponentAccessor.getCustomFieldManager(); def checklistCustomField = customFieldManager.getCustomFieldObject("customfield_10013"); def checklistCustomFieldType = checklistCustomField.getCustomFieldType(); // Create a new ChecklistItem def itemJson = ''' { "name": "Run all tests", "checked": false, "statusId": "none", "mandatory": false, "rank": 0 } '''; def ChecklistItem newItem = checklistCustomFieldType.getSingularObjectFromString(itemJson);
We have written an utility method to facilitate creation of a new ChecklistItem
object. In many of our examples, we are using this method:
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); }