Applying a change template in a Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2020 05:17 AM
Hi everyone,
I'm trying to apply a change template via Business Rule.
I would like to understand why my script is not working?
var change = new GlideRecord('change_request');
var template = new GlideRecord('std_change_record_producer');
var sys_id;
template.addQuery('name', 'TEMPLATE');
template.query();
if(template.next()){
sys_id = template.sys_id;
}
change.initialize();
GlideTemplate.get(sys_id).apply(change);
Debugging, I know I'm getting the sys_id. But I think this "GlideTemplate.get(sys_id).apply(change);" is the issue.
Could you help me?
Best regards,
Raphael Almeida Avelino
- Labels:
-
Script Debugger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2020 04:19 AM
I just looked at OOB script written on change_request table which applies standard change template to the CR.
var template = GlideTemplate.get(current.std_change_producer_version.std_change_producer.template);
template.apply(current);
Business rule name: https://dev66612.service-now.com/sys_script.do?sys_id=54a5d058eb2312002a7a666cd206fe9c
One more thing is that above script will work when we open a form manually. If we want to create a record via script and apply standard change template automatically via script then you may try below.
var rec1 = new GlideRecord("change_request");
rec1.initialize();
rec1.applyTemplate("name of template here");
rec1.insert();