Reference field dependency on UI Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2017 04:30 AM
i have a glide window open when i click a UI action. The glide window is actually UI page.
<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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 05:35 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2017 04:40 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2021 05:58 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2017 06:40 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2020 09:34 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader