Unable to call script include from reference qualifier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 08:23 AM - edited 05-16-2024 11:23 AM
Hello,
I am trying to create an advanced reference qualifier that calls a script include for a form field, however I have not been able to hit my script include yet.
My reference qualifier is:
javascript: new AMSFromSpaceRefQual().getSpaceEntitlements(current.variables.user);
And my script include:
var AMSFromSpaceRefQual = Class.create();
AMSFromSpaceRefQual.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {},
getSpaceEntitlements: function(userSysID) {
gs.info('AMSFromSpaceRefQual.getSpaceEntitlements called with userSysID: ' + userSysID);
var spaceSysIDs = [];
var userAssignedSpaces = new GlideRecord('x_nuvo_eam_users_assigned_to_location_m2m');
userAssignedSpaces.addQuery('user', userSysID);
userAssignedSpaces.query();
while (userAssignedSpaces.next()) {
var spaceSysID = userAssignedSpaces.space.getUniqueValue();
gs.info('Found spaceSysID: ' + spaceSysID);
spaceSysIDs.push(spaceSysID);
}
var result = 'sys_idIN' + spaceSysIDs.join(',');
gs.info('Returning query: ' + result);
return result;
},
type: 'AMSFromSpaceRefQual'
});
My script include is client callable and in the same scope as my variable. I have not yet been able to see any of my gs.info() statements in the application log, so it seems my script include is never being invoked at all.
Some things I've tried:
- Using the full API Name for my script include in my reference qualifier (javascript: new x_nuvo_eam.AMSFromSpaceRefQual().getSpaceEntitlements(current.variables.user);
- Passing a static value from the reference qualifier instead of (current.variables.user);
Any insight into how I can get this working would be greatly appreciated, thanks.
Edit: Both the user variable I am passing to the script include, as well as the variable my reference qualifier is on, are both part of a multi-line variable set, in case that changes something
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 11:11 AM
Is the user variable in the same variable set as the variable your ref qualifier is on? Variable sets are kind of black-box to each other and to the rest of the item, you can only access their variables from within the set itself.
I'd also try using the full API name, including the namespace, and opening the script include up. While your item might be in the same scope it may be causing a conflict if it's not being called from that scope, ie you're using a portal that isn't in that scope.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 11:21 AM
Hello Kevin,
Yes, the user field is in the same variable set as the variable I am putting this reference qualifier on. I have also tried making the script accessible from all application scopes and using the full API name and have not had any success unfortunately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 11:38 AM - edited 05-16-2024 11:43 AM
I just noticed you're using getUniqueValue. That's probably your problem. Try this:
var spaceSysID = userAssignedSpaces.space;
getUniqueValue will return the sysID, but has some caveats. First is that on the server-side we have access to the sys_id anyway. It's intended more for use on the client side, and while it can be used server side it won't return anything if you're dot-walking.
The real problem here is that you're in scope. If you tried this at global you'd get Undefined returned as a value, but in scope it will actually throw an error. Your script include is erroring out before it gets to your log statements. I've pasted the error below if you want to check your logs.
Evaluator: com.glide.script.RhinoEcmaError: Cannot find function getUniqueValue in object
Edit: you could also use userAssignedSpaces.getValue('space'). This is the preferred syntax if you're not dot-walking to a field on the referenced record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 11:32 AM
Hi @Andrew158,
When I get this situation tben i put log on each line and keep on checking how line of code is working so please put ligcand keep checking. Hope this will help you.
Please accept my solution if it resolves the query or thumbs up
Thanks
Jitendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 11:37 AM
It seems my solution involved removing the
Object.extendsObject(AbstractAjaxProcessor,
from the second line of my code, as well as making the application accessible to all application scopes and using the full API name in my reference qualifier. I am still not getting the correct results, but at least now I can see that my script include is being invoked since my gs.info() messages are logging.