Checklists defined in the HR Service Configuration get added to cases when the case is created. However, sometimes checklists are created after their are cases already in flight. The below script will add a checklist from an HR Service to an HR case if it does not already have one:
//get the sys_id of the record in the checklist table that corresponds with the HR Service
var hr_service_checklist_sys_id =
//look for records without checklists
var list = new GlideRecord([Your table name here]);
list.addEncodedQuery("active=true"); //add additional criteria here
list.query();
while (list.next()) {
//look for a checklist
var checklistGR = new GlideRecord('checklist');
checklistGR.addQuery('document', list.getUniqueValue());
checklistGR.query();
//if there isn't a checklist, create one
if (checklistGR.getRowCount() == 0) {
//create the checklist
var newChecklistGR = new GlideRecord('checklist');
newChecklistGR.initialize();
newChecklistGR.setValue('table',list.getTableName());
newChecklistGR.setValue('document',list.getUniqueValue());
var checklist_sys_id = newChecklistGR.insert();
//copy the checklist over from the HR service "template" checklist
var checklistItemGR = new GlideRecord("checklist_item");
checklistItemGR.addEncodedQuery("checklist.sys_idSTARTSWITH" + hr_service_checklist_sys_id);
checklistItemGR.query();
while (checklistItemGR.next()) {
var itemGR = new GlideRecord('checklist_item');
itemGR.initialize();
itemGR.setValue('name', checklistItemGR.name.getDisplayValue());
itemGR.setValue('order', checklistItemGR.getValue('order'));
itemGR.setValue('checklist', checklist_sys_id);
itemGR.insert();
}
}
}