Reference Qualifier to Script Include

David Post
Kilo Expert

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:

find_real_file.png

Script Include:

find_real_file.png

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).

1 ACCEPTED SOLUTION

chrisperry
Giga Sage

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

 

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

View solution in original post

8 REPLIES 8

Akif_Shah
Kilo Sage
Kilo Sage

Can you switch your reference qualifier to say "gs.getUserName()" instead of "g_user.userName"

chrisperry
Giga Sage

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

 

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

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!

find_real_file.png

find_real_file.png

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:
find_real_file.png

 

Again - thank you for pointing out those issues earlier. Still wondering where I've gone wrong!

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

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry