- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 02:54 AM
I have a table with records for contracts. When a user is trying to view the list of records, I want to automatically show them all records where one field matches the company name of the users who is currently logged in.
What is the best way to achieve this and can you please point to any good documentation?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 03:07 AM
Hi,
you can use query BR on your contracts table
Condition:
gs.getSession().isInteractive() && !gs.hasRole('admin')
Script:
I assume your company field is reference to core_company table
current.addQuery('companyField', gs.getUser().getCompanyID()); // give here the company field name
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
‎04-04-2022 02:59 AM
Create a Read ACL for this.
You will have to use the script field in the ACL to write the company logic.
Open any existing Read ACL with some script in it and you will get an idea.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 03:07 AM
So to clarify, I do have a read ACL and the user is able to see only the contracts where the two fields match.
But when he calls up the list, it initially by default doesn't show him anything until he uses the filter and searches for contracts from his company, then it displays a list.
But I would like the list to automatically filter the records based on his company name and the company name in the record as long as the user has a specific role. Is this possible and if yes is there documentation on how to achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 03:07 AM
Hi,
you can use query BR on your contracts table
Condition:
gs.getSession().isInteractive() && !gs.hasRole('admin')
Script:
I assume your company field is reference to core_company table
current.addQuery('companyField', gs.getUser().getCompanyID()); // give here the company field name
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
‎04-04-2022 03:36 AM
Thank you, I ended up creating a query business rule as you suggested. Was not aware you could specify a query BR, so cool to learn something new.