- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 08:05 AM
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();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 08:42 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 08:29 AM
That unfortunately makes sense.
Any suggestions? Sounds like I would also not be able to do this by calling a script include in the template condition, being that it is still server side. How can I invoke a client side script and do this from the browser once the record is open?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 08:33 AM
I don't have any suggestions at this time.
As far as I know, there's no way to apply the template from a client script, however any onChange client script has an 'isTemplate' flag to determine if the field was changed on account of a template or a human manually changing it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 08:42 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 09:01 AM
Thanks I'll give it a try and let you know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 09:06 AM
Also just noticed your template is setting the "parent.model category" versus the "Model category" that exists on the alm_hardware table. Is there a reason you are trying to set the parent? Change it to model_category and see if that works.