Is there a way to automatically apply a pre-defined checklist template to an incident or task (or group of them) based on the substate?

andrewdeasey
Kilo Explorer

I am looking for a way to automatically apply a pre-defined checklist template to an incident or service catalog task when a specific substate is selected.  We do QA on random incidents and tasks, and the substate determines which incidents and requests are QA'd and which are not. I know how to create the checklist template and manually assign it to an incident, but not automatically. Can anyone offer suggestions for this? Thanks!

18 REPLIES 18

On the table write a business rule with condition



If (current.substate =='mystatevalue')


{


current.applyTemplate('template-name');


}



Please mark this response as correct or helpful if it assisted you with your question.

Oh I see, you replied to the original post.



Any ideas for how to do this as a client script? I assume that's what I'd need since I want it to appear when I set a subcategory to a certain value.



Example, If Subcategory = Computer, I need the Checklist Template for computers to appear.


Ignore my previous answers which were related to sytem templates.



For a Check list template, You may need to create you own formatter.



If you navigate to formatter and search for 'checklist', you will see a record. This is linked to a Macro



find_real_file.png



You will need to create your own copy for checklist formater and link a new copy of macro.


In your custom macro, add below code and try



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <g2:evaluate>


  var isBrowserSupported = (GlideVTBCompatibility.getCompatibility() != 'block');


  var isNewUI = gs.getProperty('glide.ui.doctype', 'false') == 'true';


  var isNewRecord = true;


  if (isBrowserSupported $[AMP]$[AMP] isNewUI) {


  var sysID = current.getUniqueValue();


  var tableName = current.getTableName();


  isNewRecord = current.isNewRecord();


if (current.substate != 'mystate')


      isNewRecord = true;



  // get the checklist ID for this record


  var checklistID = null;


  var checklist = new GlideRecord("checklist");


  checklist.addQuery("document", sysID);


  checklist.addQuery("table", tableName);


  checklist.query();


  if (checklist.next())


  checklistID = checklist.getUniqueValue();


  }


  </g2:evaluate>


  <body>


  <j2:if test="$[!isNewRecord]">


  <g:macro_invoke macro="checklist_template" readonly="false" record="$[sysID]"


  table="$[tableName]" checklistid="$[checklistID]"/>


  </j2:if>


  </body>


</j:jelly>



Please mark this response as correct or helpful if it assisted you with your question.

shivanipatel
ServiceNow Employee
ServiceNow Employee

Andrew,



We are glad you took advantage of the ServiceNow Community to learn more and to get your questions answered. The Customer Experience Team is working hard to ensure that the Community experience is most optimal for our customers.



If you feel that your question was answered, we would greatly appreciate if you could mark the appropriate thread as "Correct Answer". This allows other customers to learn from your thread and improves the ServiceNow Community experience.



If you are viewing this from the Community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thanks,


Shivani Patel


Unknown-1.png


theory118
Tera Contributor

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



//Create checklist array


var checklistArr = {};



//Get checklist template


var JS_N = new GlideRecord('checklist_template');


JS_N.get('checklist_sys_id');


checklistArr = JSON.parse(JS_N.getValue('template'));



//Create checklist object


var chk = new GlideRecord('checklist');


chk.initialize();


chk.setValue('owner', checklistArr['owner']);


chk.setValue('table', 'table_name');


chk.setValue('document', current.sys_id);


chk.setValue('name', checklistArr['name']);


var checklistId = chk.insert();



//Loop through template and create checklist


for(var key in checklistArr.items)


{


var chki = new GlideRecord('checklist_item');


chki.initialize();


chki.setValue('checklist', checklistId);


chki.setValue('name', checklistArr.items[key]['name']);


chki.setValue('order', checklistArr.items[key]['order']);


chki.insert();


}



})(current, previous);