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

Vivin Verghese
Tera Guru

Can you please check since you are using  <g2:evaluate> it should be  <j2:while> or <j2:set>

Tried this. Not working.

jaheerhattiwale
Mega Sage

@Francis Renyl First of all make all g2 to g.

 

So change g2:evaluate to g:evaluate.

 

Then try

${jvar_grloc.floor.sys_id}

 

If this works then thats good else try below line

${obj.floor.sys_id}

 

Please mark as correct answer if this solves your issue.

@Francis Renyl Did you try this? If not then please try it once.

If i use g:evaluate. I am not able to access current object.