
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 07:07 AM
Good Morning Team,
I am having an issue with performance and I was hoping some of you may have run across this before and knew of a way to fix it.
The issue:
On my Incident form, I have the Caller field using an Advanced Reference Qualifier and pointing to a script include.
Without having to go into a deep dive explanation about why I am using a Script Include, suffice it to say it's required and I can't use a simple qualifier on the dictionary.
The problem is that my script include is doing a query for all active users on the sys_user table and making the pop up (magnifying glass) take 9-12 seconds to load once you click the icon.
Code:
Dictionary Entry: Advanced Ref Qualifier:
javascript:new incidentInfo().getContacts();
Script Include:
var incidentInfo = Class.create();
incidentInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getContacts : function()
{
//Get the Company
var comp = current.getValue('company');
//Define an Array to use later
var userList = [];
//Is the company filled out?
if(comp == null)
{
//Find and Return Active Users
var findUser = new GlideRecord('sys_user');
findUser.addActiveQuery();
findUser.query();
while(findUser.next())
{
var userID = findUser.getValue('sys_id');
userList.push(userID);
}
return 'sys_idIN'+userList;
}
else
{
//I have commented out this section to ensure
//Performance issue wasn't a result of this code block.
}
},
type: 'incidentInfo'
});
Can anybody see what I am doing wrong? I do have an option to promote to Production and hope that the extra processing power on our PROD instance will help with the time but I don't think that's a very elegant solution to this issue. Thoughts?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 09:59 AM
Hi,
So your user query business rule is concatenating an "active=true" essentially for users who are not admin or user_admin. So if you're testing this as yourself...as an admin...it won't apply it. So the business rule conditions aren't being met...for you...versus it not running in general for others. I'm unsure how you're testing this, but I'm pretty sure that's it, based on both my own experience and literally the tons of threads on the forums where people are asking how to get around the query business rule and if it was as easy as creating a script include instead, then that'd be what the answer is, but it's not, haha.
If you are trying to force active=true to everyone, no matter their role, then yes, you can supply it like you're doing. You are passing the query back to your reference qualifier from your script include.
My apologies, I'm not sure how else to say that you don't need the GlideRecord query, but to just say...you don't need the GlideRecord query. Please remove it...
So this whole thing could be changed to just:
getContacts : function(){
var comp = current.getValue('company');
//Is the company filled out?
if(comp == null) {
return "active=true";
} else {
//do x
}
}
So in your script in your post that you marked as Correct...there is 0 reason for a GlideRecord query to be there as it's not doing anything. Well, it's doing something, but it's pointless. Your GlideRecord is looking at the user table and if it finds at least 1 record on that table...no matter the record...then pass back active=true.
There's no point for that, so you can remove it to save performance and resources on your instance.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 07:18 AM
Hi,
Thanks. I mentioned more than just the dictionary override in my reply.
Are you saying that the out of box user query business rule has been adjusted from out of box to not filter for active users?
As that would get concatenated to any query you pull together, even from this script include.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 07:27 AM
No I did not change that rule, are you saying that if I remove the active query it will still return active users?
EDIT: I just tried to remove the active query and it returned all users (inactive as well) and still took a while to load.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 07:42 AM
Hi,
Please review the out of box business rule (user query -- on the sys_user table) I've described a few times above. This will tell you more about it than I can, if it's been adjusted, etc.
And as far as that entire section, you wouldn't need it at all. I'm unsure if you meant you removed just the active query, literally, or the entire GlideRecord, but if you're not doing the active query (which you shouldn't have to), then the entire GlideRecord there isn't needed. If you remove that as well, that should speed things up.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 07:13 AM
Hi,
which form is this?
If company is empty -> show active users
If company is not empty -> then show which users?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 07:15 AM
If the company is not empty then show users in that company, basically replacing the dependency field on the dictionary. But again I can't use the dependency field because of a requirement so I have to use a script include