- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
// 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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I tried using user_id initially and that did not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Yes. i tried running the script as a BG and it return true. But not in the UC.