How to make a ui_reference field filter dependent on a different field

alexbones
Tera Expert

Needing help developing a UI page dialog box to re-assign a ticket based upon a ui action button. Where I'm stuck is getting the UI Reference field for the assigned to field to be dependent on the assignment group.

<g:ui_form>

  <!-- Get the values from dialog preferences -->

  <g:evaluate var="jvar_short_text"

      expression="RP.getWindowProperties().get('short_text')" />

  <g:evaluate var="jvar_comments_text"

      expression="RP.getWindowProperties().get('assigned_to_text')" />

      <g:evaluate var="jvar_assignment_group"

      expression="RP.getWindowProperties().get('assignment_group')" />

     

    <!-- Set up form fields and labels -->

    <table width="100%">

        <tr id="description_row" valign="top">

              <td colspan="2">

                    <!-- Short description value used as a label -->

                    ${jvar_short_text}

              </td>

        </tr>

        <tr>

            <td>

                <!-- Assigned to input reference field -->

                <g:ui_reference name="assigned_to" id="assigned_to" table="sys_user" query="group=${jvar_assignment_group}" label="Assign to Problem Manager:"

                      mandatory="true" />

            </td>

        </tr>

        <tr>

            <td colspan="2">

            </td>

        </tr>

        <tr id="dialog_buttons">

              <td colspan="2" align="right">

                    <!-- Add OK/Cancel buttons. Clicking OK calls the validateComments script -->

                    <g:dialog_buttons_ok_cancel ok="return validateInput()" ok_type="button" cancel_type="button" />

              </td>

        </tr>

  </table>

</g:ui_form>

1 ACCEPTED SOLUTION

Here's the conceptual code (totally untested)



<g:evaluate var="jvar_users">


var ug = new GlideRecord('sys_user_grmember');


ug.addQuery('group', "${jvar_assignment_group}"); // use your jelly variable here for the group to filter


ug.query();



var list = []; // create an array of user IDs


while (ug.next()) {


        list.push(ug.getValue('user')); // add record's user to list as a member of that group


}


var users = list.join(','); // create comma separated values


users;   // save it to jvar_users


</g:evaluate>



Now you can use jvar_users as your reference qualifier in the g:ui_reference tag.


query="sys_idIN${jvar_users}"


View solution in original post

10 REPLIES 10

You are very welcome Alex. Thanks for participating in the community!


Community Alums
Not applicable

Hi Chuck,

I have the same requirement with one modification. I have created a catalogue item where i have used tow varaiables.

For ex var1 & var2. Var1 is a normal catalogue variable and var2 is a macro variable. Both var 1 & var 2 are reference field.

Based upon var1 selection i have to display some records in var2. So var2 is a macro variable i have used <g:ui_reference tag. How i can pull reference qualifier here?

 

Help me on the same.

 

Regards,

Sirraj

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Alex,



The below thread should answer your question.


How to make one ui_reference field dependent on another ui_reference in a UI Page


srividyavishnub
Kilo Contributor

Hello Guys!



I was able to filter based on this, but the filter for users is based on the Assignment group value at the form level, suppose I've the assignment group field on the GlideDialogWindow, how do I achieve this similarly?



<g:evaluate var="jvar_users">


var ug = new GlideRecord('sys_user_grmember');


ug.addQuery('group', "${jvar_assignment_group}"); // use your jelly variable here for the group to filter *********** Here I should be able to compare with the current //assignment chosen at GlideDialogWindow*****************


ug.query();



var list = []; // create an array of user IDs


while (ug.next()) {


        list.push(ug.getValue('user')); // add record's user to list as a member of that group


}


var users = list.join(','); // create comma separated values


users;   // save it to jvar_users


</g:evaluate>




I tried to achieve this using onChange script written on assignment group with a call back method, still unable to achieve this. I work on Eureka.



-Vidya


Hi Vidya,



Do you have a variable jvar_assignment_group setup to query the form you are working on and is it getting the properties from your client script?


What is the overall goal you are trying to achieve? It sounds like when you change the assignment group you want a dialog window to appear with the list of users in that group.



Here is the other part of the script that I have on my UI Action button that triggers the dialog window UI page code I have above:


Hope this helps



---------------------------


//popup dialog window to assign the the groups Problem manager. dialog box properties are stored on UI Page: problem_manager_dialog


function setAssignedTo(){


      //get fields to pass to the problem manager review dialog box      


      var assigned_to_text = g_form.getValue("assigned_to");


      var short_text = "Assign to Problem Manager:"


      var assignment_group = g_form.getValue("assignment_group");


     


      var dialog = new GlideDialogWindow("problem_manager_dialog"); //Instantiate the dialog containing the UI Page 'problem_manager_dialog'


      dialog.setTitle("Please select the assignment group's Problem Manager"); //Set the dialog title


      dialog.setPreference("assigned_to_text", assigned_to_text); //Pass the input into the dialog


      dialog.setPreference("short_text", short_text); //Pass in a short description for use in the dialog


      dialog.setPreference("assignment_group", assignment_group);


      dialog.render();//Open the dialog


     


}




Alex