- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
Tuesday
Hi Community,
I’m working in a custom scoped application and need help with a reference qualifier issue.
Requirement:
I have a Training Budget table with a reference field called division, which points to a division table which is extended from Department table. The Division table contains fields like:
- name
 - dept_head (reference to sys_user, representing the Division Manager)
 
When a user opens the Training Budget form, I want the Division field to show only those divisions where the logged-in user is the Division Manager (dept_head).
However, if the user has the admin role, they should see all divisions.
What I Tried:
I used the following onLoad client script:
But this is not working — the user still sees all division records when clicking the lens icon. Also, I noticed that g_form.setReferenceQual() throws an error in the console:
TypeError: g_form.setReferenceQual is not a function.
Additional Info:
- The app is in a custom scope.
 - The division field is a reference to a scoped table.
 - I tried setting the Reference Qualifier to Advanced in the dictionary, but it resets to Simple after saving.
 
Question:
What is the correct way to apply a dynamic reference qualifier in a scoped app so that:
- Non-admin users only see divisions where they are the dept_head
 - Admins see all divisions
 
Any working solution or workaround would be greatly appreciated!
Thanks in advance!
Solved! Go to Solution.
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
Wednesday
ServiceNow best practice for dynamic filtering is to use an Advanced Reference Qualifier with a Script Include. You create a Script Include that returns an encoded query and then call that Script Include function inside the field’s reference qualifier using the javascript: prefix.
Example setup:
Create a Script Include in your scoped application.
Name: x_training_budget_FilterDivisions , create funcation getDivisionsForUser add logic hereIn the Advanced Reference Qualifier script field, enter:
javascript: new x_training_budget_FilterDivisions().getDivisionsForUser()
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
Tuesday
you cannot apply ref qualifier using client script.
So that approach is wrong.
Simply use this in advanced ref qualifier of that field
Note: Community adds : so replace it with colon character
javascript: var query = '';
if (!gs.hasRole('admin'))
    query = 'dept_head=' + gs.getUserID();
query;
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
Tuesday
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
Wednesday
Steps I Followed:
I opened the dictionary entry for the Division field in the Training Budget table, where I want to display the division of the currently logged-in user.
I clicked the Advanced View related link, selected Advanced in the Use Reference Qualifier field, added the code you provided, and saved the changes.
Issue Observed:
After saving, the Use Reference Qualifier field resets to the default value Simple, instead of retaining Advanced.
Could you please let me know if I missed any steps or did something incorrectly?
Screenshot fyr,
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
Wednesday
steps are correct.
Try to save from List instead of Form
what's the outcome with admin and non-admin?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
