The CreatorCon Call for Content is officially open! Get started here.

Apply Standard Template for Change Request through Script

Nirmala5
Mega Contributor

Hi All,

I'm trying to create Standard Change Request through Pre-Approved Template. I'm using below script in workflow to create one, but its creating "Normal" Change request all other fields like Implement Plan, Justifications, Assignment Group, etc. are copied with same content mentioned in template. Only difference is Type of the change its inserted as "Normal"

var gr=new GlideRecord('change_request');
gr.Initialize();
gr.applyTemplate('standard_rfc');
gr.type='standard';
gr.insert();  

//This is creating Normal Change

Kindly help to find the script through which I can submit a standard change through script.

5 REPLIES 5

GBall
Tera Contributor

Hi all,

I know this thread is a couple years at this point but I stumbled across it today and ended up finding a solution.  Wanted to share in case anyone else runs into this.  The first block is intended to find the latest version of the producer; this way the script will not need to be updated as new versions are published in the future.  All you need in the sys_id of the std_change_record_producer

var producerID = 'YOUR SYS ID GOES HERE';
var templateVersion = new GlideRecord('std_change_producer_version');
templateVersion.addQuery('std_change_producer=' + producerID + '^std_change_proposal.state=3');
templateVersion.orderByDesc('version');
templateVersion.query();
templateVersion.next();

var chg = new GlideRecord('change_request');
chg.initialize();
chg.type = 'standard';
chg.state = '-5'; //new
chg.work_notes = 'Producer version: ' + templateVersion.getUniqueValue();
chg.std_change_producer_version = templateVersion.getUniqueValue(); // Sys ID of the Standard Change Templates version
var template = GlideTemplate.get(chg.std_change_producer_version.std_change_producer.template);
template.apply(chg);
chg.insert();