/
Adding items to checklists using ScriptRunner
Adding items to checklists using ScriptRunner
You may need to extend an existing checklist with additional items.
Steps
Get the custom field, custom field type and current items of your Checklist field.
def customFieldManager = ComponentAccessor.getCustomFieldManager(); // Remplace the custom field ID with whatever ID your custom field has def checklistField = customFieldManager.getCustomFieldObject("customfield_10101"); def checklistCFType = (ChecklistCFType) checklistField.getCustomFieldType(); Collection<ChecklistItem> items = (Collection<ChecklistItem>) checklistCFType.getValueFromIssue(checklistField, issue);
For each item you wish to add, you will need to create an item and append it to the retrieved collection. Make sure to set the rank of the item to the end of the checklist; if not, it may not end up where you expect.
// In this example we created a small function to help create items. // Feel free to adapt this function to better fit your use case. def addNewItem(String name, String statusId, Collection<ChecklistItem> currentItems) { ChecklistItem newItem = new ChecklistItem(); newItem.setName(name); newItem.setStatusId(statusId); newItem.setRank(currentItems.size() + 1); currentItems.add(newItem); } // Add the items by calling the function we just created addNewItem("First new item", "inProgress", items); addNewItem("Second new item", "blocked", items); addNewItem("Third new item", "none", items);
Update the custom field with the updated collection.
checklistCFType.updateValue(checklistField, issue, items);
Full example
Here is a full example where we add a few items every time the script is run.
SERVER documentation (On Cloud? Go here.)
Have questions? Contact our Service Desk for help anytime.
, multiple selections available,
Related content
Getting started with ScriptRunner
Getting started with ScriptRunner
Read with this
Updating items in checklists using ScriptRunner
Updating items in checklists using ScriptRunner
Read with this
Converting Checkboxes fields to Checklist fields using ScriptRunner
Converting Checkboxes fields to Checklist fields using ScriptRunner
Read with this
Checklist item representations
Checklist item representations
Read with this
Importing a template using ScriptRunner
Importing a template using ScriptRunner
Read with this
Running custom validations using ScriptRunner
Running custom validations using ScriptRunner
Read with this