Advanced script for User Criteria.

Divya Sharma1
Kilo Explorer

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

12 REPLIES 12

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

Both returns true for admin. 

 

Thanks!

Chetan

I want to run the code for non-admin user. whoever logs in.