Reference Qualifier to Script Include is lagging BAD!

ServiceNowSteve
Giga Guru

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?

1 ACCEPTED SOLUTION

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!

View solution in original post

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

why not just use this instead of script include?

javascript: 'active=true';

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Because the commented out section of code handles another scenario so I have to call out to the Script Include.

Allen Andreas
Administrator
Administrator

Hello,

Out of box there's a query business rule on the sys_user table called: user query, that already does this.

I assume you all modified this for this to be needed?

Otherwise, if this field is extended from task, you could create a dictionary override for this field and override the reference qualifier with a simple:

active=true

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

I can't use a dictionary override because the script include handles multiple scenarios in the coded section that I didn't include in the code sample above. One for if no company is filled out and the commented out section for if a company is filled out.