How to show users only based on logged in user company
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2026 09:53 PM
Hi,
I want to show only users in a reference variable where company is child or parent.
Example.
Case 1:
I have logged in my company will be BTS, I have another Referance varaible(sys_user) in this variable I want to show all the company users.
Case 2:
I have logged in my company will be AB Mauri, I have another Referance varaible(sys_user) in this variable I want to show only "AB Mauri BeNeFr, AB Mauri Brazil, AB Mauri Etten Leur, AB Mauri India, AB Mauri Italy, AB Mauri Malaysia, AB Mauri Mexico, AB Mauri North America, AB Mauri Pakistan, AB Mauri Philippines, AB Mauri Portugal, AB Mauri Spain, AB Mauri Sri Lanka, AB Mauri Turkey, AB Mauri UAE, AB Mauri Vietnam, Cereform, Mauri Products" company users only.
Note: All this companies are child to AB Mauri.
Case 3:
I have logged in my company will be GSC, I have another Referance varaible(sys_user) in this variable I want to show "AB Nutrition, AWorld, ABakeries, Allied Mills, GG, JR, Speedibake, Westmill " company users only.
Reference Varaible name: Business Users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2026 10:46 PM
If Company is BTS, then need to show all the company users in referance variable.
If Company is GSC, then need to show "AB Nutrition, AWorld, ABakeries, Allied Mills, GG, JR, Speedibake, Westmill" Company users only in this case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2026 10:49 PM
so it's based on logged in user's company
then do this
I believe I answered your question and you can now enhance the script based on your requirement, developer skills and experience.
javascript:
var query;
var myCompany = gs.getUser().getCompanyID();
if (myCompany == 'BTSCompanySysId')
query = ''; // means show all users
else if (myCompany == 'GSCCompanySysId')
query = 'company.nameINAB Nutrition,AWorld,ABakeries,Allied Mills,GG,JR,Speedibake,Westmill';
else if (myCompany == 'AB MauriCompanySysId')
query = 'company.parentIN' + myCompany;
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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2026 12:22 AM
Reference Qualifier:
I have added below code in reference qualifier
javascript:
var query = '';
var myCompany = gs.getUser().getCompanyID();
var BTS = '97540d483be262904b81a89704e45afd';
var ABF_CORP = '2fbf142e2b962a508a51fef56e91bf0f';
if (myCompany == BTS || myCompany == ABF_CORP) {
query = '';
}
else {
var familyRoot = myCompany;
var compGR = new GlideRecord('core_company');
if (compGR.get(myCompany)) {
while (compGR.parent) {
compGR.get(compGR.parent);
}
familyRoot = compGR.sys_id.toString();
}
query = 'company=' + familyRoot + '^ORcompany.parent=' + familyRoot;
}
query;
I have logged in with Twining's user, in business contact variable it need to show only twining's child companies, However it is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2026 12:39 AM
so what debugging did you do from your side?
Also ensure you use : and not : -> ServiceNow converts that automatically when we post that as comment
💡 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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
