/
Append items to an existing checklist
This documentation is for version 4.x. For the latest documentation, click here
Append items to an existing checklist
You may need to extend an existing checklist with additional items. In those situations, you will start by retrieving the current list of Checklist Items.
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.
def newItem = checklistCustomFieldType.getSingularObjectFromString('{"name": "item name"}');
newItem.setRank(existingChecklistValue.size() + 1);
existingChecklistValue.add(newItem);
Finally, you update the custom field passing it the same collection that was initially extracted from the custom field.
checklistCustomFieldType.updateValue(checklistCustomField, event.issue, newChecklistValue);
Following is a complete example that can be used to add two items to an existing checklist:
import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
@WithPlugin("com.okapya.jira.checklist")
import com.okapya.jira.customfields.*;
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);
}
// Retrieve the Custom Field Type for the Checklist Custom Field
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def checklistCustomField = customFieldManager.getCustomFieldObject("customfield_10013");
def checklistCustomFieldType = (ChecklistCFType) checklistCustomField.getCustomFieldType();
// Add items to the existing Checklist
def issue = (MutableIssue) event.issue;
def ArrayList<ChecklistItem> existingChecklistValue = (ArrayList<ChecklistItem>) issue.getCustomFieldValue(checklistCustomField);
def maxRank = existingChecklistValue.size();
existingChecklistValue.add( createChecklistItem(checklistCustomFieldType, "Move the folder structure", false, null, true, maxRank++) );
existingChecklistValue.add( createChecklistItem(checklistCustomFieldType, "Remove *.exe files", false, null, true, maxRank++) );
// Update the issue with the checklist
checklistCustomFieldType.updateValue(checklistCustomField, issue, existingChecklistValue);
, multiple selections available,
Related content
Update a checklist with a new set of items
Update a checklist with a new set of items
Read with this
Modifying a Checklist in a Workflow
Modifying a Checklist in a Workflow
Read with this
Enhancing checklists using Groovy scripts
Enhancing checklists using Groovy scripts
Read with this
Manipulating Checklists using Groovy Scripts
Manipulating Checklists using Groovy Scripts
Read with this
Update a checklist using the Issue Manager
Update a checklist using the Issue Manager
Read with this
Validate a Checklist
Validate a Checklist
Read with this