- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 08-03-2018 09:49 AM
Hello,
This article is about how to create a standard change request using a template in a business rule (or any server side code). It is valid for Jakarta or higher releases.
In the earlier verions, a template can be applied to a standard change request using the attribute "Template" (gr.template = "TEMPLATE_SYS_ID").
After ServiceNow updated their change template architecture to two step mode, the above statement is not valid.
You can refer to changes made to templates in Jakarta release by clicking here.
Below code helps create a change request using a change record producer template.
//*******************************************************************************************************************
var gr = new GlideRecord("change_request");
gr.newRecord();
gr.type = 'standard';
var chgProducerVersion = "d08ec5d9dbXXXXXXXXXXXXXXXXXXXXXXXX"; //sys id of the change record producer version
var chgTemplate = new GlideRecord("std_change_producer_version");
chgTemplate.get("sys_id", chgProducerVersion);
gr.start_date = gs.daysAgo(-1);
gr.end_date = gs.daysAgo(-2);
var template = GlideTemplate.get(chgTemplate.std_change_producer.template);
template.apply(gr);
gr.work_notes = "Change has been created using the template - " + chgTemplate.std_change_producer.name;
gr.insert();
//*******************************************************************************************************************
Thank you for taking a look at my article. If this helps you, please mark it as useful.
Rajesh Raya
- 5,279 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi, just to add a code remake to creat an action for Flow Designer that allow to apply a standar change tamplete to a new created recod for change request:
(function execute(inputs, outputs) {
var change = new GlideRecord("change_request");
change.addQuery('sys_id', inputs.change.getValue('sys_id'));
change.query();
if (change.next()){
var chgTemplate = new GlideRecord("std_change_producer_version");
chgTemplate.get("sys_id", change.getValue('std_change_producer_version'));
var template = GlideTemplate.get(chgTemplate.std_change_producer.template);
template.apply(change);
change.work_notes = "Change has been created using the template - " + chgTemplate.std_change_producer.name;
change.update();
} else {
change = null;
}
outputs.change = change;
})(inputs, outputs);