Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Show checklist template on task by default

Matki
Tera Contributor

Hi everyone,

I want to automate the call of a checklist template for certain changes tasks.

Matki_0-1698309738477.png

I've tried this, but I have to hardcode the coosen change task.

new ChecklistUtil().createChecklistFromTemplate('69b29e611b75f5100c420e93604bcbf7', 'change_task', '1d45b3ea1bc67150530ea9f1604bcb75');

 I want to make the last part dynamic:

new ChecklistUtil().createChecklistFromTemplate('69b29e611b75f5100c420e93604bcbf7', 'change_task', 'every change task with a specifc short_description');

Can anyone help me with the code for my business rule?

 

Thanks in advance! 

2 REPLIES 2

Anand Kumar P
Giga Patron

Hi @Matki ,

To achieve the above scenario you have to write after insert,update business rule on change_task table condition for specific short description='your sd' and use below script 

 

(function executeRule(current, previous) {
    var checklistTemplateSysId = '69b29e611b75f5100c420e93604bcbf7';
    var changeTaskTable = 'change_task';
    var specificShortDescription = 'Your Specific Short Description'; 
    var changeTaskGR = new GlideRecord(changeTaskTable);
    changeTaskGR.addQuery('short_description', specificShortDescription);
    changeTaskGR.query();
    while (changeTaskGR.next()) {
        var checklistUtil = new ChecklistUtil();
        checklistUtil.createChecklistFromTemplate(checklistTemplateSysId, changeTaskTable, changeTaskGR.sys_id);
    }
})(current, previous);

 

Please mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

  

Hey Anand,

thanks for your help! 

Unfortunately it does not work. I 've modified the code a little bit but without success...

Greetings