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 06:00 AM
If "u_hr_function" is the checkbox on the user profile you are trying to check, then you should be able to use
if (obj.u_hr_function == "true" || gs.hasRole('hr_coordinator')) {
as your if condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2018 06:22 AM
Slight correction; you would need to remove the "" around true, also it's best to get the value of the field, results can be a bit random if you reference the glide object directly.
if (obj.getValue('u_hr_function') == true || gs.hasRole('hr_coordinator')) {
//code
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2018 06:56 AM
Its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2018 06:57 AM
Its not working.