- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 07:59 AM
Hi everyone, Im trying to create an ACL where it will check if the current logged in user "location" has the same value as a custom field "u_site" which is a reference field for the "cmn_location" table. I have tried to do this with an "advanced" ACL, but it is not working, it almost looks like the ACL is not even running. Can anyone help with this please ?
Here is the code that Im using and some printscreens of the ACL:
Code:
(function() {
var userLocation = gs.getUser().getLocationID();
if (!current.u_site && !userLocation) {
return false;
}
if (userLocation != current.u_site) {
return false;
}
/* if (userLocation == current.u_site) {
answer = true;
}*/
return current.u_site == userLocation;
})();
Prints:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 09:35 AM
Hi @F_bio Santos ,
this one line is enough
current.getValue('u_site') && gs.getUser().getLocation().toString() == current.getValue('u_site');
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 08:25 AM
Try below script.
var userLocation = gs.getUser().getRecord().getValue('location'));
if (userLocation == current.u_site) {
answer = true;
}else{
answer=false;
}
Regards ,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 09:00 AM
try this
var userLocation = gs.getUser().getLocationID(); // User's location (sys_id)
var recordSite = current.u_site; // Record's u_site (sys_id)
// Allow access only if both are set and match
answer = (userLocation && recordSite) ? (userLocation === recordSite) : false;
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 09:35 AM
Hi @F_bio Santos ,
this one line is enough
current.getValue('u_site') && gs.getUser().getLocation().toString() == current.getValue('u_site');
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 09:42 AM
Its working in kind of a weird way, if the user opens it, it works but if other user with the same location open it, he cant see it