The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Apply template to inc using Scheduled Jobs

e__zcarss
Tera Contributor

Hi All

So I have this running every 20secs

 

var templateGr = new GlideRecord('sys_template');
templateGr.get('93114dcec3250210c6b0bbec050131d3'); 
if (templateGr.isValidRecord()) {
    var targetRecord = new GlideRecord('incident');
    targetRecord.get('8d6353eac0a8016400d8a125ca14fc1f'); 
    if (targetRecord.isValidRecord()) {
        templateGr.apply(targetRecord);
        targetRecord.update();
        gs.info('Template applied and incident updated');
    } else {
        gs.error('Incident not found');
    }
} else {
    gs.error('Template not found');
}

 


Problem is nothing happens. I get a log saying "Template applied and incident updated" but nothing is updated on the inc.

I know the template and inc sys_id are found because the script would error 

The template works. I can apply it manually. 
table in incident
domain is global
user is system administrator
nothing in groups
global is ticked


Thanks 

Andrew

Note: 

Got it to work:

		targetRecord.applyTemplate("20_min_awiting_user");
		targetRecord.update();




1 REPLY 1

jonsan09
Giga Sage
Giga Sage

You could try using '"applyTemplate" to your "targetRecord" instead of ".apply". More info can be found here: https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/form-adminis...