- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 02:18 AM
Hi guys,
Really trying to work something out in order to add a checklist automatically on a Task when it is created.
Tried with business rule since I did not know how to do it in the workflow.
(function executeRule(current, previous /*null when async*/) {
// Query checklist
var mcl = new GlideRecord('checklist_template');
mcl.addQuery('name','CONTAINS', "The best template");
mcl.query();
// set checklist items
if(mcl.next()){
var myListItem = new GlideRecord('sc_task');
myListItem.addEncodedQuery('request_item.cat_item=c053f28737703e00143ed2e843990ea4^state!=3^ORstate=NULL');
myListItem.orderByDesc('sys_created_on');
myListItem.setLimit(1);
myListItem.setValue('checklist', mcl.getValue('template'));
myListItem.insert();
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 02:42 AM
Hello Robin,
I use this code in the workflow catalog task to add a checklist template
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", "The best template");
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 02:42 AM
Hello Robin,
I use this code in the workflow catalog task to add a checklist template
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", "The best template");
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 04:14 AM
This worked very well!! Thank you Timmy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2019 02:06 AM
Hello Timmy,
We upgraded to London and the task is now being completed by itself. Have you experienced this?
Kind regards,
Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2019 07:12 AM
Hello Robin,
No, in our customer instances it is still working as expected.
Kind Regards,
Timmy Weytjens