The best way to create a Checklist Item object is to use the getSingularObjectFromString(String)
method of the Custom Field Type. The input to the method is a string containing a Json representation of the item.
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(); // Json representation of an item def itemJson = ''' { "name": "Run all tests", "checked": false, "statusId": "none", "mandatory": false, "rank": 0 } '''; // Create a checklist item def ChecklistItem newItem = checklistCustomFieldType.getSingularObjectFromString(itemJson);
Utility Method
If you intend to create many items, a good practice is to use an utility method to facilitate creation of a ChecklistItem
objects.
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); }