The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Advance User Criteria Scripting

vidhya_mouli
Giga Sage
// Load the user record from customer_contact table
var user = gs.getUserID();
var userGR = new GlideRecord('customer_contact');
userGR.get(user);

var parentAccountName = userGR.account.account_parent.name + '';
var targetAccountName = 'Test Super Parent 001';

var answer = (parentAccountName == targetAccountName);

 

Not sure why this script is not working.

 

5 REPLIES 5

Anand2799
Giga Guru

Hi @vidhya_mouli ,

 

Do not use gs.getUserID(); in user criteria script instead use user_id to get the current user.

 

var parentAccountName = '';
var targetAccountName = 'Test Super Parent 001';
var answer = false;

var userGR = new GlideRecord('customer_contact');
userGR.addQuery('user', user_id); //verify correct field to query data 
userGR.query();
if(userGR.next()){
 parentAccountName = userGR.account.account_parent.name + '';
}

var answer = (parentAccountName == targetAccountName);

 

Thanks

Anand 

I tried using user_id initially and that did not work.

Ankur Bawiskar
Tera Patron
Tera Patron

@vidhya_mouli 

are you sure that user has contact record?

try this

// Load the user record from customer_contact table
var user = user_id;
var userGR = new GlideRecord('customer_contact');
if (userGR.get(user)) {

    var parentAccountName = userGR.account.account_parent.name + '';
    var targetAccountName = 'Test Super Parent 001';

    answer = (parentAccountName == targetAccountName);

} else {
    answer = false;
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Yes. i tried running the script as a BG and it return true. But not in the UC.