How to cast GlideRecord?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 03:56 PM
I'm looking to cast a GlideRecord object into a child class.
What I'm trying to do is fill in a form with a field on cmdb_ci_hardware but I have to do the searching from cmdb_ci.
For example, say that there is a custom field on cmdb_ci_hardware called u_environment. When I search for a CI, I want to access that field, even though I'm searching from the cmdb_ci table.
I try this
var cmdb_ci=new GlideRecord('cmdb_ci');
cmdb_ci.addQuery('name','SomeHardware');
cmdb_ci.query();
if (cmdb_ci(next)){
gs.log(cmdb_ci.u_environment);
}
But that returns undefined because the sys_class_name of the cmdb_ci GlideRecord is "cmdb_ci" and the u_environment field is on the cmdb_ci_hardware table.
Is there any way to access that u_environment variable in this case? I tried doing a query from cmdb_ci and saying Hardware.u_environment is not empty, and it gave "ref_cmdb_ci_hardware.u_environmentISNOTEMPTY". So I tried cmdb_ci.ref_cmdb_ci_hardware.u_environment, and that crashed my Client Script.
Any help would be appreciated.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2019 10:56 PM
Yeah, I am assuming that isn't an option.
Always more ideal to query as close to the table as possible.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022