Advanced Ref Qualifier works in portal, returns 'not a function' in UI16

William Busby
Tera Guru

Real head scratcher here... I have an advanced reference qualifier that works fine if run within the portal but returns 'is not a function' when run via UI16. The details w/o the fluff:

This is all in the global scope, the catalog item and the script include being called. The script include is:

 

 

 

 

 

 

var sys_user = Class.create();
sys_user.prototype = {
    initialize: function() {
    },
	getAgencyUsers: function(agency) {
		gs.warn('global.getAgencyUsers running for agency ' + agency);
		response = [];
		try {
			var grUser = new GlideRecord('sys_user');
			grUser.addQuery('u_agency', agency);
			grUser.query();
			while (grUser.next()) {
				response.push(grUser.getUniqueValue());
			}
			gs.info('global.sys_user.getAgencyUsers returning ' + 'sys_idIN' + response.join(','));
			return 'sys_idIN' + response.join(',');
		}
		catch (ex) {
			gs.error('global.sys_user.getUsers exception - ' + ex.message);
			return; // return nothing
		}
	},
    type: 'sys_user'
};

 

 

 

 

 

Called from ARQ formatted thusly: 

 

 

javascript:new global.sys_user().getAgencyUsers(current.variables.agency)

 

 

(edited - trust me, the ':' is just ':' but I can't defeat the formatting enforced by the editor :))

 

When run via the portal the qualifier executes and returns the expected result. When executed via 'Try it' in UI16 it throws an error: 

com.glide.script.RhinoEcmaError: sys_user is not a function.
<refname> : Line(1) column(0)
==> 1: new global.sys_user().getAgencyUsers(current.variables.agency)

 

I've spent the better part of more time than I care to confess poking sticks at this to no avail. Any ideas?

11 REPLIES 11

Gangadhar Ravi
Giga Sage
Giga Sage

Hi @William Busby 

 

I don't think you need script include for this. Please try below script in your advanced reference qualifier.

 

javascript&colon;"u_anency="+current.variables.agency

 Please mark my answer correct and helpful if this works for you.

thx for the reply but this is a much slimmed down version of the SI just to illustrate the issue

Juhi Poddar
Kilo Patron

Hello @William Busby 

Potential Reason:

  • The issue you're encountering stems from how the global namespace is interpreted differently across various contexts, particularly between the Service Portal and UI16.

Workaround:

  • Your Script Include is named sys_user, which can cause conflicts because sys_user is also the name of a ServiceNow table. Using this name for your custom Script Include creates ambiguity and may override existing system behavior.
  • To resolve this, consider renaming your Script Include. This eliminates any conflict with the sys_user table and ensures that ServiceNow correctly interprets your custom Script Include.
  • Additionally, if the issue persists, you can log debug messages in your Script Include to trace how and when it is being invoked.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

thx for the reply but the name isn't an issue