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:34 PM
The value parameter is not supported in g:ui_reference, please find the syntax
<g:ui_reference name="field_name" id="DOM identifier" table="table_name" query="pass_any_query" columns="column1_name,column2_name"/>
name - The name of the field that can be used to refer to it in the processing script and JavaScript
id - The identifier to be used in the DOM element
table_name - The name of the table that the reference field will be pointing to
query - The string query value that can be used to filter data available to be selected in the field
columns - The list of columns available while selecting values
If I could help you with my response you can mark it as helpful and correct as it benefits future viewers
Thanks,
Sai Kumar B
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 10:36 PM
The documentation does not define value attribute, But when you set any location sys_id as a static value for the value attribute. It works fine. The below works fine.
td><g:ui_reference name="floor" id="floor" table="cmn_location" columns="name" value="4cf09a3797132110156e3bc3f153afd7"/></td>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 10:43 PM
You can do one thing, add a query parameter and pass your dynamic sys_id as below
query="sys_id="+pass_your_dynamic_jvar_that_contains_sys_id
So, user can see that record in the reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 11:12 PM
Tried this. Not working. I am unable to access Jelly variables in the HTML part.