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

My errors were at a higher level - and required details that I didn't include!

We're working on the Case form (sn_customerservice_case.do), and that table is in the Customer Service application scope.

I modified the script include to be accessible from all scopes, and the predicated the call to it with 'global.' so that we could call the include from the Customer Service scope. Done and done.

Thank you again for pointing out the issues with my code!

Kristy Merriam
Administrator
Administrator

I don't believe you can use g_user in this context. Try current.user_name.

Doesn't current. pull the variable value from the form? i.e., if there were a variable on the form named user_name, it would pull whatever value was in the field?

Yes, your understanding is correct. Using 'current.user_name' would not work in this context unless this reference qualifier is on the sys_user table...and even then it would be pulling in the User ID of the current user record, not the user ID of the logged-in user.

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