We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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

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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

16 REPLIES 16

Ankur Bawiskar
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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Muralidharan BS
Mega Sage

Hi kaomamichou

 

You can try

var userGR = new GlideRecord('sys_user_delegate');
userGR.get(user_id);

//check if the user is declared as manager
var gr = new GlideRecord('sys_user');
gr.addQuery('delegate',userGR.sys_id);

Also look for the catalog variable in the delegate form you used if the names arent populating. 

 

Hi Murali,

Using the code:

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('delegate',userGR.sys_id);
gr.addQuery('active', true);
gr.query();
if (gr.hasNext()) {
answer = true;

} else {
answer = false;

}}}

The delegate still not allowed to perform the request as shown on the capture 1

There is a client script(onChange) that setting values depending on the 

reqFields: Please select a contractor from your team'.

That works if the manager is performing the request.Capture(2)

Capture(1)

find_real_file.png

Capture(2)

find_real_file.png

The delegate role is set as following:

find_real_file.pngThank you 🙂 

 

Kindly,

Michou.

Hi Michou,

Kindly provide the snapshot of onchange client script what you have on the form, possibly a little tweak will help delegates filling the form. 

Regards

Murali

Hello,

Here the client script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

g_form.getReference('u_external_user',reqFields);
}
function reqFields(u_external_user){
g_form.setValue('u_first_name',u_external_user.first_name);
g_form.setValue('u_last_name',u_external_user.last_name);
g_form.setValue('u_job_title',u_external_user.title);
g_form.setValue('u_site',u_external_user.location);
//g_form.setValue('u_company',u_external_user.company);
g_form.setValue('u_contract_end_date',u_external_user.u_contract_end_date);
}

find_real_file.png

Also, have a look on the u_external_user configuration: 

find_real_file.png

Thank you 🙂

Kindly,

Michou