Advance User Criteria Scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours 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
an hour 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
2 hours 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
an hour ago
Yes. i tried running the script as a BG and it return true. But not in the UC.