Set reference fields via template

martin_chabarri
Mega Expert

Hi all,

I am trying to set Model Category and Model on the alm_hardware table via template, but am not able to do so. It seems that dot walked fields, or maybe reference dot walked fields, cannot be applied via template via script. In my script include, I am using the applyTemplate method(), and I believe this is working because all other fields are being set properly. ACL's are not an issue because I can create a new record and use the same template and it works.

HELP!

var gr = new GlideRecord(table_name);

gr.initialize();

gr.applyTemplate(template_name);

gr.setTimeout("",2000); //is it a timing issue?

gr.insert();

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

It's undocumented, but I have seen this code in Event Management business rule where you can apply a template via SysId using the following syntax:


GlideTemplate.get(template.sys_id).apply(GlideRecord)



You might want to try this instead of using applyTemplate() and see if this works.


View solution in original post

11 REPLIES 11

Used GlideTemplate and it produces the same result



It applies the template but unable to update Model and Model Category


Actually, I was wrong.



Had an error in the code, using GlideTemplate works!!!



Thank you guys so much