
- 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:48 AM
I found the answer to fixing this (I think) which comes from THIS POST and the short version on how to fix lag using a reference qualifier is to return a query and not the list of sys_id's
getContacts : function()
{
var comp = current.getValue('company');
var query ='';
//Is the company filled out?
if(comp == null)
{
//Queue the user table
var findUser = new GlideRecord('sys_user');
findUser.query();
//Change to IF instead of WHILE since we're returning a query and not a list.
if(findUser.next())
{
query = 'active=true';
}
return query.toString();
}
}
Thank you both for all of your help in figuring this out!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2022 08:11 AM
Hello,
Unfortunately, your script still doesn't make a lot of sense. You're instantiating a GlideRecord query for no reason if you're just going to return active=true.
As I mentioned above, you could just remove all that and just return what you need if the company is null.
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 08:31 AM
I am not sure I understand what you're suggesting.
The OOB user query rule is a BEFORE QUERY rule with this info:
When I query from the Script Include it will not return actives unless I specifically ask it to return actives in the SI query, this business rule does not affect the results.
So how would you suggest I form the code for this if I am not supposed to do a Glide query?

- 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-21-2022 10:21 AM
Thanks for following up and sorry for being so thick headed.
I tried this and it works without the call to the table and subsequent processing time.
Thank you again and have a great week!