We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Compare User Information on ACL against Records for Read Access

Nic Omaha
Tera Guru

Hello, I have users in 4 regions who all have "read" access to the table. They are requesting we lock read access down by location. Im struggling on the script I would write to look up users location "user.location" and if it matches current.fieldname.location then allow read. 

 

Any guidance would be appreciated! 

Nic

2 REPLIES 2

Danish Bhairag2
Tera Sage

Hi @Nic Omaha ,

 

U can try something like this

 

if(current.fieldname.location == gs.getUser().getLocation()){

answer = true;

}else{

answer= false;

}

 

Thanks,

Danish

 

Harsh_Deep
Giga Sage

Hello @Nic Omaha 

 

Use belo script

 

answer = checkUser();
function checkUser(){
var usr = gs.getUserID();
var groups = new GlideRecord('sys_user');
groups.addQuery('sys_id='+usr);
groups.query();
if(groups.next()){
if(groups.location=='your_location_name'){
return true;
}
else {
return false;
}
}

 

Please accept solution and mark as helpful, if it resolves your query.

Thanks