Create Standard Change Request using a template in a business rule
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 versionvar 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();
https://www.servicenow.com/community/itsm-articles/create-standard-change-request-using-a-template-in-a-business/ta-p/2302015