Reference field dependency on UI Page

Community Alums
Not applicable

i have a glide window open when i click a UI action. The glide window is actually UI page.

find_real_file.png

<g:ui_reference name="approver_user" id="approver_user" table="sys_user" query="active=true^roles=itil" completer="AJAXTableCompleter" />

Approver is a Reference field and queries user table. Approver Type has 3 drop down values: Responsible Manager, Accountable Director & Individual Approver

I need to modify the query based on the selection value on Approver Type so that i can query Approver field on User table as below,

Ex: query="active=true^roles=itil^u_responsible_manager"   if Approver type is Responsible Manager

Ex: query="active=true^roles=itil^u_accountable_director"   if Approver type is Accountable Director

Thanks in advance!

14 REPLIES 14

Community Alums
Not applicable

Hi Ankur,


It's not working,


document.getElementById("sys_display.user1").setAttribute("name","QUERY:active=true^nameLIKErest");



even i tried jquery $("#approver_user").val("active=true")


Community Alums
Not applicable

<g:form_label>


  Approver:


  </g:form_label>


  <g:ui_reference name="approver_user" id="approver_user" table="sys_user" query="active=true" completer="AJAXTableCompleter" />




how to access the id "approver_user" and set the query value?



i want to dynamically set the query value like "active=false" / "active=true^vip=true"   etc..



document.getElementById () returns null and not able to access the field


Hi Karthik,



I was also checking on this part in my demo instance but nothing concrete came out. So as of now no solution is present.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Community Alums
Not applicable

I really appreciate your help on this Ankur, The design part (onChange script on drop down field) made the first step. Thanks for that and looking forward from you if you achieve the same.


Hi Karthik,



I have found a way to achieve this and I have developed the script and is working fine. it is restricting the users based on the assignment group.


You can modify your script accordingly. The only difference would be :


1) you will have a drop down onChange of the drop down field get the value of drop down


2) once you get the value you can then query the table and do the necessary step



Example:


Group A - member 1, member 2


Group B- member 3, member 4


When you select Group A in first lookup and then click on the lookup icon for users it will show only 2 members/users i.e. Member 1 and Member 2


Similar is for Group B.



Here is the script.



HTML Section


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">



  Group: <g:ui_reference name="group" id="group" table="sys_user_group" completer="AJAXTableCompleter" query="active=true" onchange="setUserFilter()"/>



  Users: <g:ui_reference name="userRecords" id="userRecords" table="sys_user" completer="AJAXTableCompleter"/>


</j:jelly>



Client Script



function setUserFilter(){



var groupSysId = gel('group').value;


  var UserLookUp = gel('lookup.userRecords');



  var userArray = [];


  var gr = new GlideRecord("sys_user_grmember");


  gr.addQuery("group", groupSysId);


  gr.query();


  while (gr.next()) {


  userArray.push(gr.user.toString());


  }



  UserLookUp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'userRecords', 'not', 'sys_user', '', 'false','QUERY:active=true',           'sys_idIN" + userArray+ "', '')");


}



Please let me know if any issue while implementing this.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader