Script in Simple reference qualifier slowing down performance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 07:20 AM - edited 05-05-2025 07:22 AM
EDIT: All of the : are obviously supposed to be normal colons.
This is both a discovery and a question.
If I enter an encoded query in an Advanced reference qualifier for a catalog item, something like:
javascript: 'active=true^sys_idIN' + myScriptInclude().myFunction();
... this will work fast (under 1 second) even though the script include query is big.
If I then change the reference qualifier to 'Simple', ServiceNow will create two filters:
- Active is True
- Sys ID is javascript: myScriptInclude().myFunction();
Great, I thought, this makes it easier to read when you have a very long encoded query with more filters.
But it now takes around 3.5 seconds to fetch the data when you click the reference field. So I change the reference qual to Advanced again and see that it has now changed to:
active=true^sys_idIN javascript: myScriptInclude().myFunction();^EQ
So the ordering has changed and there is a strange-looking ^EQ at the end, but that doesn't seem to make a difference. If I save with Advanced again with the reference qual formatted like above, the response time is still around 3.5 seconds.
Only when I return the query string to the way I formatted it at first, does it become quicker again. So it would seem that:
- Starting with javascript: followed by a string followed by your actual javascript is much faster than putting the javascript: in the second part of your query.
- ServiceNow defaults to the more inefficient query.
Why is this?
Regards,
Kim

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 08:29 AM
I'm surprised the second one works at all. When using javascript as part of your advanced query, you should always format it like the first example you gave.
My guess as to why it's slower is because it's doing the first part of the query (active=true), then evaluating the script, and then doing the second half of the query. That requires 2 searches of records as opposed to one search which is done with the first one. That's completely a guess, though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 11:24 PM
Thank you Jennifer.
But what is your motivation for why we should always format a query like the first example - other than the guess you make in the second paragraph?
Your guess seems valid by the way, I am just surprised that ServiceNow will automatically format a query in the more inefficient way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 11:30 PM
I agree with @JenniferRah although we don't know how internally ServiceNow does the split if you use simple condition
We usually use the advanced script when we want to make it dynamic and the simply one is used only for simply conditions based on fields of that table
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader