Filter ui_reference in a UI Page

Michael Kaufman
Giga Guru

I have an Assignment Group and Assigned to fields on an UI Page. I want to filter the Assigned To list by "active=true^roles=itil" and the Assignment Group.

I don't know how to do this, and there isn't much documentation. Any ideas?

I tried adding "'QUERY:active=true^roles=itil" to the name, but that messes up the processing script. Also I can't figure out how to filter the users by the groups selected in this UI Page.

Here is my html:



<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<form action="ui_page_process.do">
   <input type="hidden" name="name" value="hp_planned_task_creator"/>
   <input type="hidden" id="cancelled" name="cancelled" value="false"/>
   <g:evaluate>
         var parent_task = '${sysparm_sysID}';
   </g:evaluate>
     <table>
           <tr>
                 <td nowrap="true">
                       <label>Assignment Group:</label>
                 </td>
                 <td>
                       <g:ui_reference name="assignment_group" id="assignment_group" table="sys_user_group" value="${sysparm_group_value}" displayvalue="${sysparm_group_displayvalue}"/>
                 </td>
           </tr>

           <tr>
                 <td nowrap="true">
                       <label>Assigned to:</label>
                 </td>
                 <td>
                       <g:ui_reference name="assigned_to"   id="assigned_to" table="sys_user"/>
                 </td>
           </tr>
           <tr>
                 <td nowrap="true">
                       <label>Time Card Active:</label>
                 </td>
                 <td>
                       <g:ui_checkbox name="timecard_active" value="${sysparm_timecard_active}"/>
                 </td>
           </tr>
           <tr>
                 <td nowrap="true">
                       ${gs.getMessage('Quantity')}:
                 </td>
                 <td>
                       <input name="task_quantity" id="task_quantity" value="1"/>
                 </td>
           </tr>
           <tr>
                 <td align="right"   colspan="2">
                       <g:dialog_buttons_ok_cancel ok="return true;" cancel="return onCancel();" />
                 </td>
           </tr>
     </table>
     <input type="hidden" name="parent_task" id="parent_task" value="${sysparm_sysID}"/>
</form>
</j:jelly>


1 ACCEPTED SOLUTION

Michael Kaufman
Giga Guru

I figured out how to filter the ui_reference field.



<g:ui_reference name="QUERY:active=true^roles=itil" id="assigned_to" table="sys_user" />


Then in the Processing Script, you reference that name field like this:



newTask.assigned_to = request.getParameter("QUERY:active=true^roles=itil");


Now I want to make this ui_reference field dependent on another ui_reference. For instance, I have an Assignment field and an Assigned To field. I want the assigned to dependent what the Assignment field is selected?

Is there a parameter with a ui_reference to make it dependent on another field?


View solution in original post

10 REPLIES 10

Michael Kaufman
Giga Guru

I figured out how to filter the ui_reference field.



<g:ui_reference name="QUERY:active=true^roles=itil" id="assigned_to" table="sys_user" />


Then in the Processing Script, you reference that name field like this:



newTask.assigned_to = request.getParameter("QUERY:active=true^roles=itil");


Now I want to make this ui_reference field dependent on another ui_reference. For instance, I have an Assignment field and an Assigned To field. I want the assigned to dependent what the Assignment field is selected?

Is there a parameter with a ui_reference to make it dependent on another field?


Hi Mike,



You didn't mention which Service-now release you are on. Because UI reference has changed a bit in newer release of Service-now. Because per Service now "..beginning with the Calgary release, this tag has been enhanced to allow you to specify a reference qualifier, so that the "name" attribute can be unique...."



Extensions to Jelly Syntax - ServiceNow Wiki



If you are on older releases you can still achieve this using little bit client scripting and some session data usage.



In your assignment group reference field add a onChange function updateRefQual. This function can call up a ajax script and populate a session data with current assignment group. This session data can be utilized in a utility class for eg:


var SomeUtilClass = Class.create();


SomeUtilClass.getAssignedToRefQual() {


var assignGroup =       return gs.getSession().getClientData('assignGroup');


var refQual = 'sys_user_group='+assignGroup;


return refQual;


};



<g:ui_reference name="assignment_group" id="assignment_group" onChange="javascript:updateRefQual(this.value);" table="sys_user_group" value="${sysparm_group_value}" displayvalue="${sysparm_group_displayvalue}"/>  




Now in your assigned to ui referenced field you could have a dynamic filter




<g:ui_reference name="assigned_to" name="QUERY:JSCRIPT:SomeUtilClass.getAssignedToRefQual();"   id="assigned_to" table="sys_user"/>






Hope this helps!


The post was from Jan 20, 2012, maybe pre-Aspen.   The top post says 2014, but that date was probably from the forum migration.   Time flies by!   It doesn't seem that long ago.



Thanks for the information though.  



Mike


www.servicenowelite.com


Hi Mike,



Do you have an example of this working? I have been attempting to pass an assignment group as a param to a ui page and using it in a ui_reference to filter by grouped users. Any help would be much appreciated. Thanks