Advanced script for User Criteria.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2018 05:48 AM
Dear All,
I have a requirement in which I need ti grant access to item if user has a role or has a checked box in user profile
as true.
I checked the code using logs, but inside_2 is returning.
Below is my code:
checkCondition();
function checkCondition()
{
gs.log("start");
var obj = new GlideRecord('sys_user');
obj.addQuery('sys_id',gs.getUserID());
obj.query();
gs.log("Record : "+obj.getRowCount());
while(obj.next())
{
gs.log("Inside_1");
if (gs.getUser().getRecord().getValue('u_hr_function') == true || gs.hasRole('hr_coordinator')) {
gs.log("Inside_2");
return true;
} else {
return false;
}
}
}
Please let me what needs to be changed.
Thanks in advance!
Regards,
Divya Sharma
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2018 07:57 AM
I havent tested but i think the glide user version plays the part of hasRoleExactly():
gs.hasRole('your_role') - will return true for admin as well
gs.getUser().hasRole('your_role') - will not return true for admin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2018 08:03 AM
Both returns true for admin.
Thanks!
Chetan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2018 12:09 AM
I want to run the code for non-admin user. whoever logs in.