User Criteria Advanced Script to check if user is in a under a parent company in core_company table

Scott29
Kilo Sage

Hello - I am working on creating a User Criteria record that checks if the logged-in user is in any company under a parent company.

 

On the core_company table, there is the ability to have multiple companies under 1 parent. I am looking for help with the user criteria advanced script to check to see if the logged-in user is in any company under that parent. 

1 ACCEPTED SOLUTION

SwathiPedireddy
Kilo Sage

Hi@Scott29 

 

Try following script

var user = new GlideRecord('sys_user');
user.addQuery('sys_id', user_id);
user.query();
if (user.next()) {
    var company = new GlideRecord('core_company');
    company.addEncodedQuery('name=' + user.company.getDisplayValue() + '^parent=' + 'mention your parent company sysid');
    company.query();
    if (company.next()) {
        answer = true;
    } else {
        answer = false;
    }
}

View solution in original post

2 REPLIES 2

Pratiksha
Mega Sage
Mega Sage

It is a reference field. You have to change it to list 

SwathiPedireddy
Kilo Sage

Hi@Scott29 

 

Try following script

var user = new GlideRecord('sys_user');
user.addQuery('sys_id', user_id);
user.query();
if (user.next()) {
    var company = new GlideRecord('core_company');
    company.addEncodedQuery('name=' + user.company.getDisplayValue() + '^parent=' + 'mention your parent company sysid');
    company.query();
    if (company.next()) {
        answer = true;
    } else {
        answer = false;
    }
}