Skip to content

Search Filter Behavior Reference

This page lists what a Custom Behavior on a saved-search filter can use. The script model is the same as Custom Index Behaviors, with three differences:

  • a smaller context;
  • a shorter timeout;
  • filter names in place of field names.

For where you author it, read the Introduction.

All members

Member What it does
context.username The signed-in user's identity name
context.usergroups Not defined in the query panel
context.app Not defined in the query panel
Value A filter's current value
IsVisible true when the filter is shown
IsValid true when no behavior marked the filter invalid
Style The control kind
metadataKvp The entry of the attached filter
builder.SetFilterValue Sets a filter's value
builder.SetFilterIsVisible Shows or hides a filter
builder.SetFilterIsValid Marks a filter valid or invalid
builder.SetFilterValidationMessage Adds a message under a filter
helper.GenerateUUID Returns a random UUID

Objects in scope

Object What it is
panel The filters of the saved search, keyed by filter name in your script
metadataKvp The panel entry of the filter the behavior is attached to
builder Queues changes to filters. Changes apply after the script ends.
helper helper.GenerateUUID()
context context.username only

Not available: console, fetch, XMLHttpRequest, require, import, timers, Intl. A top-level return is a syntax error.

Runtime

Item Value
Engine QuickJS (WebAssembly) in the browser
Timeout 1.5 seconds per run. The run stops and the filter shows "Behavior Custom Behavior could not be fired."
Runs when Query panel load (all behaviors, in filter order), and when the attached filter changes

context

context.username

The signed-in user's identity name.

  • Type: string
var me = (context.username || "").toLowerCase();

Apostrophes and backslashes in user names

The query panel inserts the user name into the script inside single quotes, without escaping. If a user name contains an apostrophe, every behavior on the panel fails for that user. If it contains a backslash, the backslash and the next character can change.

context.usergroups

Not defined in the query panel. It is undefined, and context.usergroups.indexOf(...) throws a TypeError.

context.app

Not defined in the query panel. It is undefined.

Filter names

In the editor, you write each filter's display name, the property title the Builder shows. When you save or select Test, the editor replaces each quoted string that exactly equals a filter name with the filter's internal key. When you open the behavior again, it shows the names.

How matching works:

  • Matching is exact and case-sensitive, inside "..." or '...'.
  • If two filters have the same name, they are numbered in filter order: "Date_1", "Date_2".
  • A name split across strings ("District " + "Council") is not replaced.
  • Any quoted string equal to a filter name is replaced, even a value.

What to watch for:

  • Names match as whole strings, so "District Council" and "District Council Name" do not collide.
  • At run time the keys of panel are internal keys. for (var k in panel) gives keys, not names.
  • If you remove a filter and add it again, it gets a new key. A behavior that named it shows a long key in place of the name when you reopen it. Fix the name and save again.

panel and metadataKvp

The editor lists four properties of a filter entry. The runtime entry also has the other index panel properties (Key, RuntimeValue, IsEnabled, Choices, SupportingMetadata). Use the four below in search.

Value

panel["Filter Name"].Value: the filter's current value, as a string. "" when empty.

var assignedTo = (panel["Assigned To"].Value || "").toString();

IsVisible

panel["Filter Name"].IsVisible: true when the filter is shown.

IsValid

panel["Filter Name"].IsValid: true when no behavior has marked the filter invalid.

Style

panel["Filter Name"].Style: the control kind, as a string. For example "Textbox", "DateTime", "DropDownList".

metadataKvp

The entry of the attached filter. metadataKvp.Value is the value that triggered the run.

builder

Each method returns builder. Changes apply after the script ends. For each method and filter, the last call wins.

builder.SetFilterValue

Sets a filter's value. Does not run that filter's behaviors.

builder.SetFilterValue(filterName, value)

Parameter Type Description
filterName string The filter's display name, as one quoted string.
value string The new value. "" clears the filter, which leaves it out of the query.

Returns: builder.

builder.SetFilterValue("Assigned To", context.username);

builder.SetFilterIsVisible

Shows or hides a filter. A hidden filter's value still goes into the query.

builder.SetFilterIsVisible(filterName, isVisible)

Parameter Type Description
filterName string The filter's display name.
isVisible boolean true shows, false hides.

Returns: builder.

builder.SetFilterIsVisible("District Council", isClerk);

builder.SetFilterIsValid

Marks a filter valid or invalid. While any filter is invalid, the search does not run.

builder.SetFilterIsValid(filterName, isValid)

Parameter Type Description
filterName string The filter's display name.
isValid boolean false marks the filter invalid. true marks it valid and clears its messages.

Returns: builder.

builder.SetFilterIsValid("Case Number", ok);

builder.SetFilterValidationMessage

Adds a message under a filter.

builder.SetFilterValidationMessage(filterName, message)

Parameter Type Description
filterName string The filter's display name.
message string The text. Never "": it shows "Could not find localized string." Do not use ;.

Returns: builder.

builder.SetFilterIsValid("Case Number", ok);
if (!ok) { builder.SetFilterValidationMessage("Case Number", "Use the form CR-2026-00123."); }

Use the four SetFilter... methods

The index panel methods (SetFieldRuntimeValue, SetFieldIsEnabled, SetFieldChoices and the shorthands) exist in the same engine, but the search editor does not list them. Use the four SetFilter... methods in search. Never use SetChoices: it is broken.

helper

helper.GenerateUUID

Returns a random UUID.

helper.GenerateUUID()

  • Parameters none
  • Returns A string. Not cryptographically secure.

How filter values reach the query

  • Empty value The filter is left out of the query.
  • Hidden with a value The filter stays in the query. Clear the value if a hidden filter must not apply.
  • Invalid filter If any filter is invalid when the user runs the search, the search does not run. The invalid filter gets focus, and the user sees "Failed to execute search. Correct highlighted filters and try again."
  • No values If no filter has a value, the search does not run and the panel asks for a value.

Allowed behavior types

On a filter, the Behaviors tab of Customize Filter offers every behavior type that the index panel offers for the filter's control, except:

  • Multi Key Automatic Indexing
  • AI Confidence
  • OCR Confidence

A filter on an identity property (a user or group) offers only the default value behavior for its control. You cannot add a Custom Behavior to it. To set it from a script, attach the script to another filter. The value format an identity filter expects is not documented here.

Permissions

Creating, editing and saving filter behaviors needs the Create/Share Saved Searches feature permission. Without it, the behavior editor opens view-only.