Debugging Search Filter Behaviors¶
A Custom Behavior on a saved-search filter runs in QuickJS in the user's browser, with a 1.5 second limit and no console. Each section below starts from what you see, gives the cause, and gives the fix.
Start with the browser developer console (F12, Console tab): the host logs script errors there. For the objects and limits, see the Search Filter Behavior Reference.
Summary¶
| Symptom | Group |
|---|---|
| Behavior could not be fired | Errors |
| The script fails as soon as it is saved | Errors |
| Every behavior on the panel fails for one user | Errors |
| Search blocked by an invalid filter | Errors |
| Could not find localized string | Errors |
| Interrupted in the console | Errors |
| The wrong filter changes | Wrong result |
| A group check never matches, or throws | Wrong result |
| Results are limited by a filter you hid | Wrong result |
| The filter fills again after the user clears it | Wrong result |
Errors¶
Behavior could not be fired¶
- Message
Behavior Custom Behavior could not be fired. - Where Under the filter. Nothing from the script applies.
- Cause One of the three causes below.
- Script error The script threw an error, for example
console.log(...),context.usergroups.indexOf(...)(it isundefinedin the query panel),panel["Wrong Name"].Value, or a top-levelreturn. - Time limit The script ran longer than 1.5 seconds.
- Filter name A
buildercall named a filter that does not exist. - Fix Open the browser console and open the search again. A script error shows as an object with a
name(ReferenceError,TypeError,SyntaxError) and amessage. - Timeout A timeout shows an
InternalErrorwith the messageinterrupted. - Bad name A bad filter name in a
buildercall logs nothing. Check every name.
The script fails as soon as it is saved¶
- Cause When you save, the editor replaces each quoted filter name with an internal key. A name that is wrong, built with
+, or in different case is not replaced, sopanel["Name"]isundefinedat run time and reading.Valuethrows aTypeError. - Fix Write each name as one quoted string, exactly as the Builder shows it. Two filters with the same name are
"Name_1"and"Name_2". - See Reference: filter names
Every behavior on the panel fails for one user¶
- Cause The user name contains an apostrophe. The query panel puts the name into the script inside single quotes without escaping, which is a syntax error for every behavior on the panel.
- Backslash A backslash in a name changes the name instead.
- Fix There is no script-side fix. Report it to support with the user name format.
Search blocked by an invalid filter¶
- Message
Failed to execute search. Correct highlighted filters and try again. - Cause A behavior marked a filter invalid with
SetFilterIsValid(name, false). The search runs only when every filter is valid. The invalid filter gets focus. - Fix Make sure the happy path calls
SetFilterIsValid(name, true), and that the user can see the invalid filter.
Hidden invalid filters
A hidden invalid filter blocks the search with no visible way to fix it.
Could not find localized string¶
- Message
Could not find localized string.under a filter - Cause The script called
SetFilterValidationMessage(name, ""). - Fix Never pass an empty message.
SetFilterIsValid(name, true)clears messages.
Interrupted in the console¶
- Message
interruptedin the console - Cause The run passed 1.5 seconds.
- Fix Remove loops over large lists and complex regular expressions. A filter behavior should read a few values and set a few filters.
Wrong result¶
The wrong filter changes¶
- Cause One of the three causes below.
- Value literal A value string that equals a filter name was replaced by a key too.
- Older save The script was saved on an earlier release, when similar names such as "District Council" and "District Council Name" could be mixed up.
- Re-added filter A filter was removed and added again. The saved script still holds the old key, which shows as a long ID when you reopen the behavior.
- Fix Rename the filter or avoid the value literal. Open the behavior, check each name, replace any long ID with the filter name, and save it again.
A group check never matches, or throws¶
- Cause In the query panel
contexthas onlyusername.context.usergroupsandcontext.appareundefined. - Fix Use one saved search per group, shared with that group.
- See Show or Hide Filters by Group
Results are limited by a filter you hid¶
- Cause A hidden filter's value still goes into the query.
- Fix Clear it with
SetFilterValue(name, "")when you hide it, if it must not apply.
The filter fills again after the user clears it¶
- Cause The behavior runs every time its filter changes. A script that fills an empty filter sees the empty value and fills it again.
- Fix This is how the runtime works. Tell users, or give them a second saved search without the default.
Show values while you test¶
In the Builder, open the filter's Custom Behavior and select Test. The script runs against the preview panel. Write what you need to see into a message on a filter you use for testing:
var keys = [];
for (var key in panel) {
keys.push(panel[key].Style + "=" + JSON.stringify(panel[key].Value));
}
builder.SetFilterValidationMessage("Case Number", "DEBUG user=" + context.username + " filters: " + keys.join(", "));
for (var key in panel) gives internal keys, not filter names, so the script lists each filter's control kind and value. Remove debug code before you save the final version, and never pass "" as a message.