petercawdron
Kilo Guru

Checklists are cool but they're horribly underutilised. They're a great way of reducing the number of tasks involved in a process and can be set up from Flows. 

find_real_file.png

Here's the code for a checklist utility that can be called from business rules, UI actions and Flows. The two functions are:

  • Create (pass the sys_id for the record and a comma separated list of your checklist items)
  • isComplete (pass the sys_id for the record to see if the checklist has been completed)
var checklistHelper = Class.create();
checklistHelper.prototype = {
	initialize: function() {
	},

	//////////////////////////////////////////////
	create: function(table, sys_id, items){

		var checklistID;
		var check = new GlideRecord('checklist');
		check.setWorkflow(false);

		if (!check.get('document', sys_id)) {
			check.document = sys_id;
			check.table = table;
			checklistID = check.insert();
		}else{
			checklistID = check.sys_id.toString();
		}

		for (var i = 0; i < items.length; i++) {
			var checklistItem = new GlideRecord('checklist_item');
			checklistItem.setWorkflow(false);
			checklistItem.initialize();
			checklistItem.checklist = checklistID;
			checklistItem.complete = false;
			checklistItem.name = items[i];
			checklistItem.order = i;
			checklistItem.insert();
		}

	},

	//////////////////////////////////////////////
	isComplete: function(sys_id){

		var checklistComplete = true;
		 
		var check = new GlideRecord('checklist');
 
		if(check.get('document', sys_id)) {
 
			var checklistItem = new GlideRecord('checklist_item');
			checklistItem.query('checklist',check.sys_id);
			
			while(checklistItem.next()){
				if(!checklistItem.complete){checklistComplete = false;}
			}	
		}

		return checklistComplete;
	},
	type: 'checklistHelper'
}; 

Then from a business rule, it's really easy to check to see if someone has completed their checklist.

(function executeRule(current, previous /*null when async*/) {

	var myCheckList = new checklistHelper();
	var checklistFinished = myCheckList.isComplete(current.sys_id.toString());
	
	if(!checklistFinished){
		current.setAbortAction(true);
		gs.addErrorMessage('You cannot close this task until the checklist is complete');
	}

})(current, previous);

Now we've got our code sitting in a Script Includes we can use it anywhere, including in Flows. So here's a custom action that was added to allow a checklist to be added to any record in a flow.

find_real_file.png

Then when you create tasks in a Flow you can quickly and easily add a checklist to the tasks you're creating along the way. 

find_real_file.png

I've included the flow action and all of this code in the attached update set (JDS) Checklists, so try it out in your development instance. 

Have fun

Comments
GB14
Kilo Patron

Hi Peter, 

We have checklist enabled on the sc_task form but the checklist is only being used in 2-3 catalogs. 

Any way we can hide the checklist field from 1 sc_task and leave it available on another?

Thanks,
Gurbir

 

Terje Monsen
Kilo Contributor

I would like to run the checklist isComplete function in a client side script every time an item in a checkbox is checked, however I cannot select "Checklist" from the field name when creating an onChange event:

find_real_file.png

 

Is there any way to check this client side when items are checked? If so, how?

 

Rahul Singh6
Tera Contributor

Super helpful. Saved a few hours for me 🙂 

Kousalya Alagap
Tera Contributor

Thanks its useful and getting better knowledge on checklist . Have doubt on Business rule Step, what is the trigger condition ? and on which table we are creating this business rule? @petercawdron 

Kousalya Alagap
Tera Contributor

@Terje Monsen did u find your answer for getting checklist field ?

GPenetito
Mega Expert

Can you build a report for checklists? Have looked in the PPM Task table and can't find a field to use

Community Alums
Not applicable

@petercawdron , How to get the selected Checklist items using onChange client Script ?

I want to display a confirm box upon selecting a "Select all" checklist item and check all checklist options.

 

Pascal Verdieu
Mega Sage

@petercawdron When importing the Checklist Helper XML, there are several errors while importing.  Just to be 100% sure, I redid a new PDI.  Running on Utah if that helps...

 

PascalVerdieu_0-1713212858926.png

 

aradhanadub
Tera Explorer

Hi, Can I enable checklist only for one single catalog Item and I want to enable this on RITM.

Community Alums
Not applicable

Hello @aradhanadub ,

Yes, we can enable the checklist only for one RITM. Below is the code: 

 

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", "Checklist Items for Laptop request");
    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();
        }
    }
 

Hopefully this gives you some ideas about how to publish checklist for a single RITM.

P.S. Please mark as helpful and/or correct if this answered your question.

Version history
Last update:
‎10-20-2019 09:11 PM
Updated by: