You might may need to extend an existing checklist with additional items, this page will demonstrate how to achieve this.
To add items, retrieve the custom field value and then add the desired items to it:
. In those situations, you will start by retrieving the current list of Checklist Items.
Code Block | ||
---|---|---|
| ||
// Add an item to the Checklist def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField); |
You then create an item and append it to the retrieved collection. It’s important that you set the rank of the item to the end of the Checklist, otherwise it may not end up where you expect it to be.
Code Block |
---|
def newItem = checklistCustomFieldType.getSingularObjectFromString('{"name": "item name"}');
newItem.setRank(existingChecklistValue.size() + 1);
existingChecklistValue.add(newItem);
// Update the issue with the new checklist
|
Finally, you update the custom field passing it the same collection that was initially extracted from the custom field.
Code Block | ||
---|---|---|
| ||
checklistCustomFieldType.updateValue(checklistCustomField, event.issue, newChecklistValue); |
...
Here Following is a complete example that adds can be used to add two items to an existing checklist:
...