g:ui_reference in UI Macros
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 09:52 PM
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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 10:46 PM
Can you please check since you are using <g2:evaluate> it should be <j2:while> or <j2:set>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 06:33 AM
Tried this. Not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 10:59 PM
@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.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 11:30 PM
@Francis Renyl Did you try this? If not then please try it once.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 06:33 AM
If i use g:evaluate. I am not able to access current object.