g:ui_reference in UI Macros

Francis Renyl
Tera Contributor

Hi.,

I am trying to build a UI Macros on CMDB CI. Which will show Location Hierarchy for the same CI record. 

I am unable to access zone,zoneName,floor,floorName,room,roomName,building and buildingName in HTML part of the code.

Ex : <td><g:ui_reference name="floor" id="floor" table="cmn_location" columns="name" value="${jvar_grloc['floor'].sys_id}"/></td> -> Here, i am not able to access ${jvar_grloc['floor'].sys_id}. I have tried using ${zone},${obj['floor'].sys_id} and still not able to solve it.

Thanks for the help in advance.

 

 

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g2:evaluate var="jvar_grloc" object="true">
		var obj={"floor":{sys_id:"",name:""},"room":{sys_id:"",name:""},"building/structure":{sys_id:"",name:""},"zone":{sys_id:"",name:""}}
		var floor,room,zone,building,location_type;
		var gr=new GlideRecord('cmdb_ci');
		gr.addQuery('sys_id',current.sys_id);
		gr.query();
		if(gr.next()){
			gs.info('COMING HERE');
			var currentLocation=gr.location;
			gs.info('current'+currentLocation);
			<j:set var='jvar_loop' value='0'/>
			<j:while test="${jvar_loop lt 4}">			
				gs.info('Location is '+currentLocation.name+'Location Type is'+currentLocation.cmn_location_type);
				obj[currentLocation.cmn_location_type.toString()].sys_id=currentLocation.sys_id.toString();
				obj[currentLocation.cmn_location_type.toString()].name=currentLocation.name.toString();
				currentLocation=currentLocation.parent;
			<j:set var='jvar_loop' value='${jvar_loop + 1}'/>
		</j:while>
		}
		var zone=obj["zone"].sys_id;
		var zoneName=obj["zone"].name;
		var room=obj["room"].sys_id;
		var roomName=obj["room"].name;
		var floor=obj["floor"].sys_id;
		var floorName=obj["floor"].name;
		var building=obj["building/structure"].sys_id;
		var buildingName=obj["building/structure"].name;
		obj;
		gs.info('Location'+JSON.stringify(obj));
	</g2:evaluate>
	
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td><label for="floor" >Floor:  </label></td>
				<td><g:ui_reference name="floor" id="floor" table="cmn_location" columns="name" value="${jvar_grloc['floor'].sys_id}"/></td>
			</tr>
		</table>
</j:jelly>

 

 

 

13 REPLIES 13

@Francis Renyl Then make all j to j2.

 

Then try

$[jvar_grloc.floor.sys_id]

 

If this works then that's good else try below line

$[obj.floor.sys_id]

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

I have tried that.. Still output is not as expected

Ankur Bawiskar
Tera Patron
Tera Patron

@Francis Renyl 

you are querying the cmdb_ci table and storing the information in json object.

but you are not using the json object.

Is this your requirement?

1) show only those locations in the reference field which belong to the current CI's location

If not then what's your actual use-case?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hey @Ankur Bawiskar . Yes. My use case is in CMDB CI. I have to find a way to show the location hierarchy information. For example. If i take a location of type zone. It has a parent location of type room which in turn has parent location of type floor. Now i need to show these values without adding any custom fields or by dot walking. I was guessing that a UI Macro would work here.