- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 02:56 AM
I want have created a custom table containing username and company as a reference field to the user table. Now the table data should be only accessible to the user if his name and company matches with the one in the custom table. How do I do that? please provide a solution by using ACL or ACL and Scripted REST API both.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 03:00 AM - edited ‎06-06-2025 03:00 AM
// Get current user details
var user = gs.getUser();
var userID = user.getID(); // sys_id
var userCompany = user.getCompanyID(); // sys_id
// Check if current record matches current user and their company
answer = (current.user == userID && current.company == userCompany); This you can write on acl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 03:07 AM
Hello @SohamJ,
Use this script in the ACL to restrict access:
(function() {
var currentUser = gs.getUserID(); // sys_id of current user
var userCompany = gs.getUser().getCompanyID(); // user's company sys_id
return current.u_user == currentUser && current.u_company == userCompany;
})();
Please mark my solution as helpful and accepted for future reference
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 03:00 AM - edited ‎06-06-2025 03:00 AM
// Get current user details
var user = gs.getUser();
var userID = user.getID(); // sys_id
var userCompany = user.getCompanyID(); // sys_id
// Check if current record matches current user and their company
answer = (current.user == userID && current.company == userCompany); This you can write on acl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 03:07 AM
Hello @SohamJ,
Use this script in the ACL to restrict access:
(function() {
var currentUser = gs.getUserID(); // sys_id of current user
var userCompany = gs.getUser().getCompanyID(); // user's company sys_id
return current.u_user == currentUser && current.u_company == userCompany;
})();
Please mark my solution as helpful and accepted for future reference
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 03:19 AM
you can use table level READ ACL and it's an easy one
what did you start with and where are you stuck?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader