- 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 07:08 AM - edited 03-10-2023 07:09 AM
That's strange, I have tried what I believe to be exactly the same code but on the sn_agent_cmdb_ci_agent ttable and get a blank result:
Rich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 07:16 AM
Hi @Ryax1 ,
Please check the actual table name of the location table being referenced in the location field on the sn_agent_cmdb_ci_agent table.
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 07:26 AM
Yes I've just double checked and confirm it is definitely the cmn_location table being referenced.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 07:28 AM
can you try this?
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.location.getDisplayValue();
gs.print(loc);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 07:30 AM
Hey @Ankur Bawiskar ,
No luck with that code either I'm afraid, still returns blank like before 😞
Richard