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

Hi Karthik,



The above solution works but one enhancement I did:


1) I am making the 2nd reference lookup as editable false on form/body load and once user selects the group then in order to allow the user to lookup the users i am making the second reference as editable again.



This avoid/takes care of the following scenario


User does a lookup from user table first and then does group lookup. So here the onChange script will show only 2 users since filter query will be applied but since user is already populated in the reference field it will still show the older value and form can get submitted.



The things marked as BOLD are the extra additions to the script as compared to my earlier comment.So this script is the modified script which you can try



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">


<html>


<body onload="makeReadonly()">


  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"/>


 


</body>


</html>


</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+ "', '')");


 


// make this as editable so that user can select from lookup


var a = gel('sys_display.userRecords');


a.removeAttribute("disabled"); // removing the disabled attribute


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


b.removeAttribute("disabled"); // removing the disabled attribute



}



function makeReadonly(){


// make the second lookup as readonly on form/body load


var a= document.getElementById('sys_display.userRecords');


a.setAttribute('disabled','true');


var b=document.getElementById('lookup.userRecords');


b.setAttribute('disabled','true');


}




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

Hi Karthik,



Any update on this. Were you able to achieve the requirement?



if yes then please mark the answer as correct also mark helpful and hit like. This helps in closing the thread for the question and also helps other to find the answers quickly.



Thanks in advance.


Regards


Ankur


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

Hi Ankur,

 

I have a similar query where I am supposed to bring the values(sub -category)based upon a field values(category)

 

Nothing is happening when I click on it

 

Regards,

Urvashi

Hi Karthik,



Can you mark my answer as correct and helpful if you are able to achieve your requirement. This helps in removing this question from unanswered list.


Thanks in advance.



Regards


Ankur


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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Karthik,

Any update on this?
Can you mark my answer as correct, 👍 helpful if you were able to achieve the requirement. This enables other members to learn from this thread.

Regards

Ankur

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