Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Advance User Criteria Scripting

vidhya_mouli
Tera 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.

 

1 ACCEPTED SOLUTION

vidhya_mouli
Tera Sage

This script worked

var answer = false;
targetAccountName = "Test Super Parent 001";

var userGR = new GlideRecord('customer_contact');
userGR.addQuery("sys_id", user_id);
userGR.addQuery("account.account_parent.name",targetAccountName);
userGR.query();

answer = userGR.hasNext();

 

The issue was caching. Everytime before I impersonate someone, I had to do cache.do and then impersonate to make it work.

View solution in original post

6 REPLIES 6

@vidhya_mouli 

in background script you passed which contact user's sysId?

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

vidhya_mouli
Tera Sage

This script worked

var answer = false;
targetAccountName = "Test Super Parent 001";

var userGR = new GlideRecord('customer_contact');
userGR.addQuery("sys_id", user_id);
userGR.addQuery("account.account_parent.name",targetAccountName);
userGR.query();

answer = userGR.hasNext();

 

The issue was caching. Everytime before I impersonate someone, I had to do cache.do and then impersonate to make it work.