- 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:07 AM
Can you include a screenshot of the dot-walked/reference fields in the template that are giving you the trouble?
My suspicion is that templates set values on a record for a specific table and update that record. If you are trying to set fields on other records in other tables, that's not going to work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 08:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 08:19 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 08:25 AM
I think I understand. Thanks Martin.
So here's what's happening behind the scenes... The template field is stored as an encoded query (same as a list filter) to set values. Example:
active=true^Name=New computer
When you invoke this via the UI by clicking the template name, it is parsing and placing the values on the various form fields. You save them when you hit Submit.
It is as I suspected... When you do this via script, you are actually trying to set a field (parent.model_category) on another table. The gr.insert(), is only updating the data for the "gr" record, not the parent. As far as I know, there's no single method to set fields on record A, and related fields on record B with one method (e.g. update the dot-walked fields.)