Script include with queryNoDomain called from filter

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2020 06:31 PM
I am writing a function that queries a domain separated table to be used as a filter from the URL. To publish the function in a Script Include, the record must be marked as Client callable, similar to AJAX server-side code. All good. However, I'm finding that queryNoDomain returns no data. I understand that queryNoDomain is not supported for client scripting, but I'm 99% sure this code runs server-side. Here's a simple example:
var _test = Class.create();
_test.prototype = {
initialize: function() {},
testQueryNoDomain: function() {
var gr = new GlideRecord('task');
gr.setLimit(10);
gr.queryNoDomain();
var returnVar = [];
while (gr.next()) {
returnVar.push(gr.sys_id.toString());
}
return returnVar;
},
testQuery: function() {
var gr = new GlideRecord('task');
gr.setLimit(10);
gr.query();
var returnVar = [];
while (gr.next()) {
returnVar.push(gr.sys_id.toString());
}
return returnVar;
},
type: '_test'
};
If you call both functions from a background script, both return the 10 sys_ids:
gs.print(new _test().testQueryNoDomain());
gs.print(new _test().testQuery());
But if you call them as a sysparm_query on the URL, queryNoDomain returns no results (from global, as admin).
yourinstance/nav_to.do?uri=%2Ftask_list.do%3Fsysparm_query%3Dsys_idINjavascript:new%2520_test().testQueryNoDomain()
yourinstance/nav_to.do?uri=%2Ftask_list.do%3Fsysparm_query%3Dsys_idINjavascript:new%2520_test().testQuery()
Is there any way to accomplish a cross-domain query similar to this from the URL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 09:08 AM
Hello!
Two Ideas:
1. Setting the Script Include to 'Public'
2. Modifying the User's Session Domain
----------------------------------------------------------------
1. Setting the Script Include to 'Public'
Place this as its own function within your Script Include (the Standard Practice, though I don't know if it is THE Best Practice, for this is to place it as the very first function within the Script Include):
/**
* Allow public access to this processor
*/
isPublic: function() {
return true;
}
I'm going to tentatively say this won't solve it, but it's a simple step to try before we attempt to modify a User's Session and their Domain on the fly.
----------------------------------------------------------------
2. Modifying the User's Session Domain
To modify a User's Domain in their Session, we can use:
gs.getUser().setDomainID('gobal'); // Set the User's Domain to Global
If you want to dynamically set a User's Domain, or just run through EVERY Domain, we can use something like this:
gs.getUser().setDomainID('gobal'); // Set the User's Domain to Global to begin
fnMainFunction; // The 'Global' Domain does not exist within the Domain table, so we must call it separately
fnSetUserDomain(); // This then runs through each Domain and processes the fnMainFunction in those Domains
gs.getUser().setDomainID('gobal'); // Return the User to the Global Domain after completion
function fnMainFunction() {
/*
// Place
// Logic
// Here
*/
}
function fnSetUserDomain() {
var grDomain = new GlideRecord('domain');
grDomain.query();
while(grDomain.next()){
gs.getUser().setDomainID(grDomain.sys_id);
fnMainFunction();
}
}
----------------------------------------------------------------
Please let me know if either of these work!
Thank you,
Nick

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 04:15 PM
Thank you Nick. All seemed like they might have an impact, but none worked.
There appear to be some limitations related to calling a script include object method from the URL context. I can't find any documentation to corroborate it.
Does anyone know what the rules are? So far, here are some other things that do not work from the URL, but do work from background script context:
gs.log()
gs.eventQueue()
gs.getUser().setDomainID()
and, of course, GlideRecord.queryNoDomain()