Forked from asimpkin/create_checklist_from_UI_action.br
Created
September 29, 2019 13:42
-
-
Save bajpaik/a4596ffd4b6ee8049d51fc7fef0fdafb to your computer and use it in GitHub Desktop.
Business Rule to create checklist and items from a given template into a task record
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The following business rules have been disabled to prevent worknotes from checklist/item changes | |
https://central1.service-now.com/sys_script_list.do?sysparm_query=GOTOnameLIKECRUD | |
*/ | |
// Get the template data with the checklist items | |
var gr = new GlideRecord('checklist_template'); | |
gr.get('dcc0b5e6373fa200afb4d02783990ef5'); // TEST TEMPLATE | |
var json = JSON.parse(gr.template); | |
// Create a checklist record for the current task | |
var cl = new GlideRecord('checklist'); | |
cl.initialize(); | |
cl.document = current.sys_id ; | |
cl.table = current.sys_class_name ; | |
cl.name = current.number ; | |
var cl_sys_id = cl.insert(); | |
// loop through each checklist template item and create an item record | |
for(var i = 0; i < json.items.length; i++) { | |
var ci = new GlideRecord('checklist_item'); | |
ci.initialize(); | |
ci.name = json.items[i].name; | |
ci.order = json.items[i].order; | |
ci.checklist = cl_sys_id; | |
ci.insert(); | |
} // end for each items | |
current.update() ; | |
action.setRedirectURL(current) ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment