How to automatically add a saved checklist to a task?

robinsnow
Tera Contributor

Hi guys,

Really trying to work something out in order to add a checklist automatically on a Task when it is created.

Tried with business rule since I did not know how to do it in the workflow.

(function executeRule(current, previous /*null when async*/) {
	
	// Query checklist
	
	var mcl = new GlideRecord('checklist_template');
	mcl.addQuery('name','CONTAINS', "The best template");
	mcl.query();
	
	// set checklist items
	if(mcl.next()){
	var myListItem = new GlideRecord('sc_task');
	myListItem.addEncodedQuery('request_item.cat_item=c053f28737703e00143ed2e843990ea4^state!=3^ORstate=NULL');
	myListItem.orderByDesc('sys_created_on');
	myListItem.setLimit(1);
	myListItem.setValue('checklist', mcl.getValue('template'));
	myListItem.insert();
	}
	
})(current, previous);
1 ACCEPTED SOLUTION

timmyweytjens
Tera Expert

 Hello Robin,

I use this code in the workflow catalog task to add a checklist template        

 var theList = new GlideRecord("checklist");
 theList.initialize();
 theList.table = "sc_task";
 theList.owner = gs.getUserID();
 theList.document = task.setNewGuid();
 var listId = theList.insert();

var checklistArr = {};

var grTemplate = new GlideRecord("checklist_template");
grTemplate.addQuery("name", "The best template");
grTemplate.query();
if(grTemplate.next())
{
         checklistArr = JSON.parse(grTemplate.getValue('template'));
 
         //Loop through template and create checklist
         for(var key in checklistArr.items)
         {
               var chki = new GlideRecord('checklist_item');
               chki.initialize();
               chki.setValue('checklist', listId);
               chki.setValue('name', checklistArr.items[key]['name']);
               chki.setValue('order', checklistArr.items[key]['order']);
               chki.insert();
          }

}

 

View solution in original post

10 REPLIES 10

ty_roach
Tera Guru

The problem with the OOB checklists is that they are unreliable, meaning, people can change the content of the checklist item after the fact, add items, delete items, change items.  There's also no guarantee that the same checklist will appear for same situation.  There is no way to restrict who can edit the checklist or when it can be edited (like do you really want people changing checklist responses after the record has been closed).

Enter Checklist Pro.  We built Checklist Pro to solve all those problems and more.  Checklist Pro application administrators can define when checklists get created and associated with records in a table (any table - not just those that extend TASK), when these checklists can be edited, when the associated record is considered "closed" (and thus should prohibit further checklist updates).  We even added the ability to define "Required" checklist items that allow enforcement, thereby preventing a record from closing unless the required items are completed.  We've built convenience Database Views to go with the most common checklist tables, which include TASK, SYSAPPROVAL_APPROVER, CMDB_CI.

They work in the Service Portal as well as in the Classic UI.

They'll work with other Scoped Applications (like HR or SecOps or even custom scoped apps & tables).

For more information contact TyGR LLC or goto our youtube channel to see it in action.