- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 12:46 AM
Hi
I want a user criteria to both match user group and a location that is on the user.
But this doesn't work. Do I have to script? I am novice at scripting, How would such a script look?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 07:48 AM
Hi,
I would encourage to have step by step debug
1) check if member of Hardware is able to access the catalog
Keep Script as: Test with user
answer = gs.getUser().isMemberOf('Hardware');
Next
2) check if user's location condition is satisfied
Keep Script as: Test with user having that location
answer = ifScript();
function ifScript(){
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', gs.getUserID());
user.addQuery('location', '25ab9d720a0a0bb300793d3a6b891f82');
user.query();
var locationValid = user.hasNext();
return locationValid;
}
3) Now combine both the codes and check by adding logs
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
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
06-18-2020 02:44 AM
Hi,
Did you add logs to verify which flag is not coming as true
answer = isValid();
function isValid(){
var isMember = gs.getUser().isMemberOf('Hardware');
gs.info('isMember is ' + isMember);
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', gs.getUserID());
user.addQuery('location', '25ab9d720a0a0bb300793d3a6b891f82');
user.query();
var locationValid = user.hasNext();
gs.info('locationValid is: ' + locationValid);
if(isMember == true && locationValid == true){
return true;
}
else{
return false;
}
}
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
06-18-2020 03:28 AM
I tried this script. Now no-one can see it, regardless :-P. I tried it in my own instance and then impersonated a user that is both member of hardware and the adress and she cannot access it at all.
Isn't it enough to have Hardware in the group and only base script solely on the location?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 03:35 AM
Hi Daniela,
through above script when both condition match then it would evaluate to true
What came in for logs did you check
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
06-18-2020 04:46 AM
so the logs doesnt really tell me anything.
I removed your script and added it again and saved and then tried again. If a user does not have neither location or hardware, it cannot access at all
But if the user has the hardware but not the location, it can access
in logs it says:
locationValid is: false |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 04:55 AM
Hi,
please try this
answer = isValid();
function isValid(){
var isMember = gs.getUser().isMemberOf('Hardware');
gs.info('isMember is ' + isMember);
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', gs.getUserID());
user.addQuery('location', '25ab9d720a0a0bb300793d3a6b891f82');
user.query();
var locationValid = user.hasNext();
gs.info('locationValid is: ' + locationValid);
if(isMember.toString() == 'true' && locationValid.toString() == 'true'){
return true;
}
else{
return false;
}
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader