Advanced User Criteria

kaomamichou
Kilo Expert

Dear All,

I've created a catalog item that provide managers the option to declare and create a new external login account.

There is a user criteria giving access to the cat item only to managers.

An evolution is requeried:

Managers want to allow their delegate to also declare and create a new external login account.

I've created the following 

checkCondition();
function checkCondition(){

//get the identified user
var userGR = new GlideRecord('sys_user_delegate_list');
userGR.get(user_id);

//check if the user is declared as manager
var gr = new GlideRecord('sys_user');
gr.addQuery('delegate',userGR.getValue('sys_id') );
gr.addQuery('active', true);
gr.query();
if (gr.hasNext()) {
answer = true;
} else {
answer = false;
}

}

After test, it's not working and delegates can not access to the cat item.

Could some one help me,

Thank you in advance!

Kindly,

Michou.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it should be like this; there is no delegate field on sys_user table

please update as below

checkCondition();
function checkCondition(){

// check if logged in user is delegate of someone

var userGR = new GlideRecord('sys_user_delegate');
userGR.addQuery('delegate', user_id);
userGR.query();
if(userGR.next()){
    

// now logged in user is delegate
// check if the user present in the delegate table is manager

var gr = new GlideRecord('sys_user');
gr.addQuery('manager', userGR.getValue('user'));
gr.addQuery('active', true);
gr.query();
if (gr.hasNext()) {
answer = true;
} else {
answer = false;
}

}


Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

16 REPLIES 16

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

error here; please correct below the table should be sys_user_delegate and not sys_user_delegate_list

var userGR = new GlideRecord('sys_user_delegate');

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks a lot!

Hi Ankur,

The delegate can now access to the form, thank you.

But, as you can see on the bellow pictures, the delegate can't perform the request:

1. Form accessible by the "Manager

find_real_file.png 

2. Form accessible by "Delegate"

find_real_file.png

RaghavSh
Kilo Patron

There is a typo in your table name.

Remove list from sys_user_delegate


Raghav
MVP 2023