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
The input to the method is a string containing a Json representation of the item.
Code Block | ||
---|---|---|
| ||
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(); // CreateJson representation aof newan ChecklistItemitem 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
Info |
---|
If you intend to create many items, a good practice is to use an utility method to facilitate creation of a |
...
|
...
objects. |
Code Block | ||
---|---|---|
| ||
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); } |