multiple <g:ui_reference> fields in a UI page

xiaix
Tera Guru

UI Page containing multiple UI fields that need the same query on the same table.   One would assume that you can give a ui_reference tag a unique ID, as told here you can: http://wiki.servicenow.com/index.php?title=Extensions_to_Jelly_Syntax#.3Cg:ui_reference.2F.3E, but that's not true.

Here's a visual of an example:

Screen Shot 10-20-15 at 02.47 PM.JPG

And the code:

<g:ui_reference name="QUERY:location=${jvar_userLoc}" id="testOne" table="sys_user" />

<g:ui_reference name="QUERY:location=${jvar_userLoc}" id="testTwo" table="sys_user" />

And when we pull up the UI page and inspect the element:

10-20-2015 2-57-25 PM.png

So the obvious question:     How can I get multiple <g:ui_reference> fields that query the same table with the same query filter onto a UI page with different input id's?

1 ACCEPTED SOLUTION

Valor1
Giga Guru

David, you have to create a unique ID for each element. If you need to set a query, set the "query" attribute, not the "name" because, as you point out, the Name gets set as the input name when the HTML is generated:




  <g:ui_reference name="user_location1" id="testOne" table="sys_user" query="location=${jvar_userLoc}" />


  <g:ui_reference name="user_location2" id="testTwo" table="sys_user" query="location=${jvar_userLoc}" />


View solution in original post

5 REPLIES 5

Valor1
Giga Guru

David, you have to create a unique ID for each element. If you need to set a query, set the "query" attribute, not the "name" because, as you point out, the Name gets set as the input name when the HTML is generated:




  <g:ui_reference name="user_location1" id="testOne" table="sys_user" query="location=${jvar_userLoc}" />


  <g:ui_reference name="user_location2" id="testTwo" table="sys_user" query="location=${jvar_userLoc}" />


This worked perfectly!   However, just to note, if I do the following:



<g:ui_reference query="location=${jvar_userLoc}" name="testName" id="testID" table="sys_user" />



It results in this:



<input id="testName" name="testName" onchange="; setLightWeightLink('testName')" type="hidden" value="206713176fb76900da584e8f1e3ee425">




So whatever you set as the ui_reference "name" will become the input "name" AND "id".



Although this has no ill-effect on me, other's may want to be aware.



I would like to know though why the wiki (http://wiki.servicenow.com/index.php?title=Extensions_to_Jelly_Syntax#.3Cg:ui_reference.2F.3E) talks about being able to put a ui_reference "id" in there when clearly it gets stripped when rendered by the browser.


I also just realized that you can't stylize the field:



<g:ui_reference style="display:none;" query="location=${jvar_userLoc}" name="input_u_s4_site_leader" id="input_u_s4_site_leader" table="sys_user" />



style="display:none;" will not work.     To apply an inline CSS style to this, is my only option to do it through JavaScript once the page has been rendered?


style="display:none;"


style="display:none;"


The ui_reference is just an OOB UI Macro, so if you open it up, you can see exactly what it does.



You you could copy and enhance the existing code to accept a style attribute, but then you'd have to call it using <g:inline macro="ui_reference_custom"> or similar.