<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Show Display Values from reference field in Glide Record query in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502236#M975243</link>
    <description>&lt;P&gt;Hi &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/294347"&gt;@Sai Shravan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks for the suggestion, this was my thought too but I wasn't sure if there was a more efficient way to do it.&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Rich&lt;/P&gt;</description>
    <pubDate>Fri, 10 Mar 2023 14:56:05 GMT</pubDate>
    <dc:creator>Ryax1</dc:creator>
    <dc:date>2023-03-10T14:56:05Z</dc:date>
    <item>
      <title>Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502197#M975231</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    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);
	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;If I change the loc variable to show the sys id it prints it perfectly:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var loc = svs.getDisplayValue("sys_id");​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;Rich&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 14:37:56 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502197#M975231</guid>
      <dc:creator>Ryax1</dc:creator>
      <dc:date>2023-03-10T14:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502209#M975235</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/281120"&gt;@Ryax1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The issue is happening because the "location" field on the "sn_agent_cmdb_ci_agent" table is a reference field.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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());
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Shravan&lt;BR /&gt;&lt;EM&gt;If my answer solved your issue, please mark my answer as Correct &amp;amp; Helpful&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 14:44:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502209#M975235</guid>
      <dc:creator>Sai Shravan</dc:creator>
      <dc:date>2023-03-10T14:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502230#M975241</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/281120"&gt;@Ryax1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;If I've helped guide you correctly in this thread, please also consider marking it as "&lt;STRONG&gt;Accept Solution&lt;/STRONG&gt;".&lt;/P&gt;&lt;P&gt;Thanks and take care!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 14:53:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502230#M975241</guid>
      <dc:creator>Sai Shravan</dc:creator>
      <dc:date>2023-03-10T14:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502236#M975243</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/294347"&gt;@Sai Shravan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks for the suggestion, this was my thought too but I wasn't sure if there was a more efficient way to do it.&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Rich&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 14:56:05 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502236#M975243</guid>
      <dc:creator>Ryax1</dc:creator>
      <dc:date>2023-03-10T14:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502257#M975251</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/281120"&gt;@Ryax1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried on cmdb_ci table, below snippet is for the reference.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SaiShravan_0-1678460617085.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/246456i3547CCF84FF7094C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SaiShravan_0-1678460617085.png" alt="SaiShravan_0-1678460617085.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SaiShravan_1-1678460638289.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/246458i0AF5416971DFC6AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SaiShravan_1-1678460638289.png" alt="SaiShravan_1-1678460638289.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:04:06 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502257#M975251</guid>
      <dc:creator>Sai Shravan</dc:creator>
      <dc:date>2023-03-10T15:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502269#M975255</link>
      <description>&lt;P&gt;That's strange, I have tried what I believe to be exactly the same code but on the&amp;nbsp;&lt;SPAN&gt;sn_agent_cmdb_ci_agent t&lt;/SPAN&gt;table and get a blank result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="result.JPG" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/246460i36FADE14F2C43BDD/image-size/large?v=v2&amp;amp;px=999" role="button" title="result.JPG" alt="result.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Rich&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:09:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502269#M975255</guid>
      <dc:creator>Ryax1</dc:creator>
      <dc:date>2023-03-10T15:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502277#M975260</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/281120"&gt;@Ryax1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please check&amp;nbsp;the actual table name of the location table being referenced in the &lt;EM&gt;location&lt;/EM&gt; field on the &lt;EM&gt;sn_agent_cmdb_ci_agent&lt;/EM&gt;&amp;nbsp; table.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:16:06 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502277#M975260</guid>
      <dc:creator>Sai Shravan</dc:creator>
      <dc:date>2023-03-10T15:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502292#M975268</link>
      <description>&lt;P&gt;Yes I've just double checked and confirm it is definitely the cmn_location table being referenced.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:26:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502292#M975268</guid>
      <dc:creator>Ryax1</dc:creator>
      <dc:date>2023-03-10T15:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502295#M975270</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/281120"&gt;@Ryax1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can you try this?&lt;/P&gt;
&lt;P&gt;var svs = new GlideRecord("sn_agent_cmdb_ci_agent");&lt;BR /&gt;svs.addQuery('agent_extended_info.cmdb_ci.sys_class_name', 'cmdb_ci_computer');&lt;BR /&gt;svs.query();&lt;BR /&gt;while (svs.next()) {&lt;/P&gt;
&lt;P&gt;var loc = &lt;STRONG&gt;svs.location.getDisplayValue()&lt;/STRONG&gt;;&lt;BR /&gt;gs.print(loc);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:28:15 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502295#M975270</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2023-03-10T15:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502297#M975272</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;No luck with that code either I'm afraid, still returns blank like before &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Richard&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:30:51 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502297#M975272</guid>
      <dc:creator>Ryax1</dc:creator>
      <dc:date>2023-03-10T15:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Show Display Values from reference field in Glide Record query</title>
      <link>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502309#M975276</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/294347"&gt;@Sai Shravan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;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 "&lt;SPAN&gt;agent_extended_info.cmdb_ci.location" instead of just 'location'.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the working script:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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);
	}&lt;/LI-CODE&gt;&lt;P&gt;Rich&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:38:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-display-values-from-reference-field-in-glide-record-query/m-p/2502309#M975276</guid>
      <dc:creator>Ryax1</dc:creator>
      <dc:date>2023-03-10T15:38:58Z</dc:date>
    </item>
  </channel>
</rss>

