How to check for empty reference field in user criteria

PascalG
Tera Expert

Hello, i'm knowledge manager and need to prevent external users from accessing a Knowledge base.
External users have a company so I'm testing the content of company field in sys_user table but it does not work (works in System Def script background though). An undefined or empty company field should return true.

User criteria diag with internal user answers false and i dont understand why.

checkCondition();
function checkCondition() {
/* access not allowed for users linked to a company */
   
    var my_user = new GlideRecord('sys_user');
    my_user.get('user_id');
    if(my_user.getValue('company') == null) {
        return true;
    }
    if(my_user.getValue('company') == undefined) {
        return true;
    }
    else {
        return false;
    }
}
 
Thanks for your help.
1 ACCEPTED SOLUTION

Rohit  Singh
Mega Sage

Hi @PascalG 

 

You need to pass the value of user_id so that the Glide Record can extract the record. In you case you are not passing any value.

 

e.g: my_user.get('user_id;,current.user_id);

 

If my response helped, please mark it helpful and accept the solution so that it benefits future readers.

 

Regards,
Rohit

View solution in original post

4 REPLIES 4

Rohit  Singh
Mega Sage

Hi @PascalG 

 

You need to pass the value of user_id so that the Glide Record can extract the record. In you case you are not passing any value.

 

e.g: my_user.get('user_id;,current.user_id);

 

If my response helped, please mark it helpful and accept the solution so that it benefits future readers.

 

Regards,
Rohit

Thanks Rohit, will test in the next minutes and come back to you.

Hello Rohit, i used 

current_user=gs.getUser(); 
and seems to be working fine.
Thanks a lot

Hi @PascalG ,

 

Glad that I was able to help you. Would you please also mark my responses as helpful.

 

It will be really for helpful for me.

 

Regards,

Rohit