Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Show Display Values from reference field in Glide Record query

Ryax1
Tera Guru

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

1 ACCEPTED SOLUTION

Ryax1
Tera Guru

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

View solution in original post

10 REPLIES 10

Ryax1
Tera Guru

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