- 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 03:08 AM
Hi
Write a Query business rule like below
current.addQuery('company_name' , gs.getUser().getCompanyID());
if company name is reference then this will work or else tweak above to make it work.
Mark my answer as correct or hit like based on impact.
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 03:08 AM
Hi ServiceLater,
Creating an ACL or using query BR will work for this. Use BR if you want 'security constraint' error doesn't appear.
I let you some useful docs:
Query BR: https://community.servicenow.com/community?id=community_blog&sys_id=240af05ddb010cd44819fb24399619ca
Best practices for creating ACL: https://community.servicenow.com/community?id=community_article&sys_id=ac67a4ccdb36e300f0612183ca961906
If it was helpful, please give positive feedback,
Thanks.
☆ Community Rising Star 22, 23 & 24 ☆