How do i trigger a standard change template in a workflow run script

Marcus23
Kilo Contributor

Hi, 

I have Standard Change Template i would like to trigger in a run script on a workflow. 

I tried this first 

"

var rec1 = new GlideRecord("incident");

rec1.initialize();
rec1.applyTemplate("my_incident_template");

"
a solution from the playbook. But i didn't work.

So when googling I found this thred in the community

https://community.servicenow.com/community?id=community_question&sys_id=054e0beddb9cdbc01dcaf3231f96..."

In that thred that this template is a template out of a recordproducer and that why the playbook solution from activate a template didn't work.

So now i have been googling to mush, involving friends a colleags and reading the thread i linked, but getting nowhere.

So do we have any ServiceNow-Ninja, whitchdoctor, superskilled community member that can give this some thought and apply a solution that explains how it works and what to do?

Take care!

Marcus

6 REPLIES 6

Harish Murikina
Tera Guru

Hi Marcus,

Please try the below code.

var templateSysId = "8d795606376897c09d3b861754990ed2"; // sysid of the  template
var incidentRecord = new GlideRecord('incident');
incidentRecord.initialize();
GlideTemplate.get(templateSysId).apply(incidentRecord);
incidentRecord.insert();

Regards,

Harish Murikinati.

With out trying i'am not sure that this is the correct solution since there is something with that u need to call the template with the right version. But i'will try this and mark your solution correct if it is. But not sure for now that this will help me 🙂 

And as i sad allso, it is not an incident, it is a standard change i whant to create 😃 the playbook solution i pointed to was the servicenow answer on how to create a incident with a template 🙂 That didn't work since the Standard Change Template is created out of a record producer if i have understood it correctly

Hi Marcus,

This Should work

var templateSysId = "8d795606376897c09d3b861754990ed2"; // sysid of the standard change templte template
var changeRecord = new GlideRecord('change_request');
changeRecord.initialize();
GlideTemplate.get(templateSysId).apply(changeRecord);
changeRecord.insert();

Regards,

Harish Murikinati.