Why is next() returning false for non-admin users?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 01:50 PM
Initially I thought this might be related to the user's issue in this thread, but as it's a fairly old and unanswered thread, I'll open this up here with my own specific use case details.
I have a very simple function inside a Script Include that I'm trying to call through a filter. Here's the code, without all the logging statements cluttering it.
getPinnedArticleIds: function() {
var result = [];
var kbGR = new GlideRecord("kb_knowledge_keyword");
kbGR.query();
while (kbGR.next()) {
result.push(kbGR.getValue('knowledge'));
}
return result;
}
This I call through a filter on the kb_knowledge table (either through GlideRecord's addEncodedQuery or directly through the list view filter UI, both give the same results) using
"sys_idINjavascript: new SPKBHelper().getPinnedArticleIds();".
Essentially I'm just trying to grab the sys_ids of all "featured" articles in our instance. What's odd is that it works just fine when run as an admin, but when I'm trying to use it through a filter as a standard user (that is, a user without any special roles or groups) it returns no results, just an empty array. Additionally, when I've got all my logging set up (see below), just before I enter the loop, I find that getRowCount() is returning the expected number of articles, hasNext() is returning true, but next() returns false. So the query is definitely finding the records in the table, it just can't iterate through them, which is why nothing's being returned. My guess is this has something to do with security permissions, because by default a standard user doesn't have read access via the kb_knowledge_keyword ACL?
After going through a whole slew of other Community threads, I've also tried using _next() rather than next(), and have renamed my GlideRecord var to random absurd names, to avoid potential random conflict with other scripts. Unfortunately, neither of those have made a difference.
getPinnedArticleIds: function() {
var result = [];
var kbGR = new GlideRecord("kb_knowledge_keyword");
kbGR.query();
gs.print('SPKBHelper - Rows: '+kbGR.getRowCount()); // Returns the correct # of "featured" articles we have
gs.print('SPKBHelper - hasnext '+kbGR.hasNext()); // Returns true
var keepIterating = kbGR.next(); // Returns false
gs.print('SPKBHelper - keepIterating: '+keepIterating);
gs.print('SPKBHelper - start while');
while (keepIterating) {
gs.print('SPKBHelper - next');
result.push(kbGR.getValue('knowledge'));
gs.print('SPKBHelper - '+kbGR);
gs.print('SPKBHelper - '+kbGR.getValue('knowledge'));
gs.print('SPKBHelper - '+kbGR.getDisplayValue('knowledge'));
gs.print('SPKBHelper - '+kbGR.getDisplayValue('keywords'));
keepIterating = kbGR.next();
}
gs.print('SPKBHelper - end while');
gs.print(result);
return result;
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 02:36 PM
At this point, I am not sure what to say. But, GlideRecord queries should work irrespective of roles. Is it working if you use it in any server script like business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 02:56 PM
Oh yeah, thank you so much for helping me find the alternative route there, yours are definitely the most correct/helpful answers I've been able to gather so far. I feel like I might just have to take this up with HI as far as this other stuff because the behavior is just so odd.
Yeah, that script include function and the query loop itself both seems to work just fine running either from any server scripts, it's just that "javascript: " function call from a filter that's acting up. I'd almost be okay with it if calling it through the filter like that didn't work at all, it's just the fact that it does work for admins that's really confusing me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 03:04 PM
Not sure but, this looks more like an ACL issue on script include table. May be the non-admin users were not able to access that script include. Give them the read access to the script include and see if it works.