- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2017 05:32 PM
I have a few checklists that I need to set on catalog tasks that are created from a workflow
I have tried to create a Business Rule on the sc_task table to have the list with items appear on insert
The checklist comes up but not the items in the BR,
What am I missing, and how can I do this in a Workflow.
Thank you
THis is the BR I am testing with
The sys_id is the catalog task sys_id for the checklist I am trying to test with.
(function executeRule(current, previous /*null when async*/) {
// Query for my Service's checklist
var myServiceId = "25709abbdbc5b20089757bedbf9619ff";
var mcl = new GlideRecord('checklist');
mcl.addQuery('table', 'sc_task');
mcl.addQuery('document', myServiceId);
mcl.query();
// Copy checklist items from my Service's checklist
var myListItem = new GlideRecord('checklist_item');
myListItem.addQuery('checklist', myListItem.getUniqueValue());
myListItem.orderBy('order');
myListItem.query();
while (myListItem.next()) {
myListItem.setValue('checklist', checkListId);
myListItem.insert();
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2017 06:55 PM
Hi Patricia,
I have just adjusted your script.
(function executeRule(current, previous /*null when async*/) {
// Query for my Service's checklist
var myServiceId = "25709abbdbc5b20089757bedbf9619ff";
var mcl = new GlideRecord('checklist');
mcl.addQuery('table', 'sc_task');
mcl.addQuery('document', myServiceId);
mcl.query();
// Copy checklist items from my Service's checklist
var myListItem = new GlideRecord('checklist_item');
myListItem.setValue('checklist', mcl.getValue('sys_id'));
myListItem.insert();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2017 06:55 PM
Hi Patricia,
I have just adjusted your script.
(function executeRule(current, previous /*null when async*/) {
// Query for my Service's checklist
var myServiceId = "25709abbdbc5b20089757bedbf9619ff";
var mcl = new GlideRecord('checklist');
mcl.addQuery('table', 'sc_task');
mcl.addQuery('document', myServiceId);
mcl.query();
// Copy checklist items from my Service's checklist
var myListItem = new GlideRecord('checklist_item');
myListItem.setValue('checklist', mcl.getValue('sys_id'));
myListItem.insert();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2017 03:46 PM
Thank you Srini
I actually was able to get it working with the following:
Now I need to try and convert that to a script include and then do a query for other templates.
It was actually a checklist template
var getTemplate = new GlideRecord('checklist_template');
getTemplate.addQuery('sys_id', 'e8a2fa43db05320089757bedbf9619ee');
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2018 12:06 PM
FWIW, if you want to have the checklist logic in your workflow rather than in a business rule, you can do this:
https://community.servicenow.com/community?id=community_article&sys_id=93840e54db4d67001cd8a345ca9619b9