Business rule to add checklist automatically on catalog task

Meenal Gharat
Giga Guru

Hi All,

How can I add Checklist template automatically on catalog task on the bases of Catalog item.

For eg : I have an catalog item named as 'Printer toner' on this catalog task it should display the checklist template  eg ('printer toner checklist')  Likewise for other catalog item it should display the checklist which is created for those specific item in catalog task.

Below is my business script which is working fine , but it is displaying same checklist template for all catalog task.

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

var getTemplate = new GlideRecord('checklist_template');

getTemplate.addQuery('sys_id', 'a67c9775db797300a477874239961985');

getTemplate.query();

if(getTemplate.next()) {
var itemJSON = new JSON().decode(getTemplate.template);
var name = itemJSON['name'];
var items = itemJSON['items'];
var owner = itemJSON['owner'];
// create checklist
var table = current.getTableName();
var checklistId = '';
var list = new GlideRecord('checklist');
list.addQuery('document', current.sys_id + '');
list.addQuery('table', table);
list.query();
if (!list.next()) {
list.document = current.sys_id + '';
list.name = name;list.owner = owner;
list.table = table;
checklistId = list.insert();
// create checklist items
for (var i = 0; i < items.length; i++) {
var item = new GlideRecord('checklist_item');
item.checklist = checklistId;
item.complete = false;
item.name = items[i]['name'];
item.order = items[i]['order'];
item.insert();

}
}
}

})(current, previous);

 

Any help or suggestions would be helpful.

Thanks and Regards,

Meenal

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

can you add the log in your glide record to check the row count. 

 

i am adding one thread here, which has quite same requirement. hope it will help you

 

https://community.servicenow.com/community?id=community_question&sys_id=fd76439cdbe66f406c1c02d5ca96...

View solution in original post

2 REPLIES 2

Harsh Vardhan
Giga Patron

can you add the log in your glide record to check the row count. 

 

i am adding one thread here, which has quite same requirement. hope it will help you

 

https://community.servicenow.com/community?id=community_question&sys_id=fd76439cdbe66f406c1c02d5ca96...

Meenal Gharat
Giga Guru

Hi Harshvardhan,

 

I checked the above link and it is working fine,  but then if I have to run the script on all workflow's---> catalog task.

Is there any way I can use single script for all catalog task checklist on the bases of catalog Items requested.

 

Thanks and regards,

Meenal