- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2025 04:54 AM
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
‎10-29-2025 05:46 AM
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
‎10-29-2025 05:24 AM
Correcting my previous reply: I'm seeing all division records in the 'Division' field of the Training Budget form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2025 05:59 AM
it should work.
Any extra query BR applied on sys_user other than OOTB one?
💡 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
‎10-29-2025 05:46 AM
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
‎10-29-2025 06:11 AM
Thank you so much! The solution using an Advanced Reference Qualifier with a Script Include worked perfectly. I was able to filter the Division field based on the logged-in user's role as Division Manager, and allow full access for admins. Appreciate the guidance! 🙌