- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 12:49 PM
I've done something wrong, and I don't seem to actually be calling my script include. And if I am, I'm not seeing it in the debugger, and definitely not getting the expected results:
Reference Qualifier:
Script Include:
When a user searches for an assignment group, if they have a specific value set in their Company attribute, they should only see a subset of available Assignment Groups. My test user always sees all the groups, causing me to think I'm either failing to call the function -OR- I'm always falling into the 'else' part of the script (which they shouldn't be).
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 12:55 PM
Hi there,
A couple of things:
1. You cannot chain together GlideRecord methods like you currently have coded, each method needs to include the GlideRecord object like userCheck.method(). So something like this instead:
var userCheck = new GlideRecord('sys_user');
userCheck.addQuery('user_name', userID);
userCheck.addQuery('company', 'company_sys_id');
userCheck.query();
2. In your reference qualifier where you have g_user.userName, replace that with gs.getUserName() which is the proper method for retrieving logged-in user's user ID via server script. The g_user class is meant to be used from client-side scripts.
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 12:55 PM
Can you switch your reference qualifier to say "gs.getUserName()" instead of "g_user.userName"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 12:55 PM
Hi there,
A couple of things:
1. You cannot chain together GlideRecord methods like you currently have coded, each method needs to include the GlideRecord object like userCheck.method(). So something like this instead:
var userCheck = new GlideRecord('sys_user');
userCheck.addQuery('user_name', userID);
userCheck.addQuery('company', 'company_sys_id');
userCheck.query();
2. In your reference qualifier where you have g_user.userName, replace that with gs.getUserName() which is the proper method for retrieving logged-in user's user ID via server script. The g_user class is meant to be used from client-side scripts.
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 01:40 PM
Christopher,
I modified the GlideRecord query to use the formatting you suggested above (1), as well as leveraging gs.getUserName() in the reference qualifier (2). Thank you!
Despite the changes, I still keep failing over into the 'else' catch. I'm thinking it is the userCheck.next() part, because with a quick look at the user table it should bein the 'if' portion:
Again - thank you for pointing out those issues earlier. Still wondering where I've gone wrong!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 01:49 PM
Hmm, that is weird, the code looks good to me now.
You could potentially try changing the userCheck.next() to userCheck.hasNext() , but honestly that shouldn't make a big difference I don't think.
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry