- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:36 AM - edited 03-10-2023 06:37 AM
Hi all,
I am trying to run a query on the Agent Client Collectors table and then get the display value of the location field. I have tried with the below script however the result is blank:
var svs = new GlideRecord("sn_agent_cmdb_ci_agent");
svs.addQuery('agent_extended_info.cmdb_ci.sys_class_name', 'cmdb_ci_computer')
svs.query();
while (svs.next()) {
var loc = svs.getDisplayValue("location");
gs.print(loc);
}
If I change the loc variable to show the sys id it prints it perfectly:
var loc = svs.getDisplayValue("sys_id");
From what I can see the issue is because the location field is a referenced field as other reference fields also do the same thing.
One solution I thought of is getting the sys_id and then querying the cmn_location table using that sys_id but this seems inefficient.
Please could someone with a little more scripting knowledge than myself explain why this is happening and if their is a simpler solution than my one proposed above?
Many thanks
Rich
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 07:38 AM
Hi @Ankur Bawiskar and @Sai Shravan ,
Thanks for both of your help, I have found the cause of this issue which was the Location field I was referencing, it needed to be "agent_extended_info.cmdb_ci.location" instead of just 'location'.
Here is the working script:
var svs = new GlideRecord("sn_agent_cmdb_ci_agent");
svs.addQuery('agent_extended_info.cmdb_ci.sys_class_name', 'cmdb_ci_computer')
svs.query();
while (svs.next()) {
var loc = svs.getDisplayValue("agent_extended_info.cmdb_ci.location");
gs.print(loc);
}
Rich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:44 AM
Hi @Ryax1 ,
The issue is happening because the "location" field on the "sn_agent_cmdb_ci_agent" table is a reference field.
var svs = new GlideRecord("sn_agent_cmdb_ci_agent");
svs.addQuery('agent_extended_info.cmdb_ci.sys_class_name', 'cmdb_ci_computer');
svs.query();
while (svs.next()) {
var loc = new GlideRecord('cmn_location');
loc.get(svs.location.sys_id);
gs.print(loc.getDisplayValue());
}
Regards,
Shravan
If my answer solved your issue, please mark my answer as Correct & Helpful
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:53 AM
Hi @Ryax1 ,
If I've helped guide you correctly in this thread, please also consider marking it as "Accept Solution".
Thanks and take care!
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:55 AM - edited 03-10-2023 06:56 AM
Hi @Sai Shravan ,
Thanks for the suggestion, this was my thought too but I wasn't sure if there was a more efficient way to do it.
Unfortunately I've just tried the code you suggested and still doesn't return the display value of the location, does this work for you?
Thanks
Rich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 07:04 AM
HI @Ryax1 ,
I have tried on cmdb_ci table, below snippet is for the reference.
Shravan
Please mark this as helpful and correct answer, if this helps you