ACL not working/running

F_bio Santos
Kilo Sage

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:

F_bioSantos_0-1748271504259.png


F_bioSantos_1-1748271516345.png

 

 

1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

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

 

View solution in original post

5 REPLIES 5

J Siva
Tera Sage

Hi @F_bio Santos 

Try below script.

var userLocation = gs.getUser().getRecord().getValue('location'));
if (userLocation == current.u_site) {
        answer = true;
}else{
      answer=false;
}

Regards ,

Siva

Ankur Bawiskar
Tera Patron
Tera Patron

@F_bio Santos 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Chaitanya ILCR
Kilo Patron

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

 

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