Skip to content

Show or Hide Filters by Group

A county records office has one "Case Lookup" search for two teams. Clerks need the District Council filter. Other staff should not see it, and it must not limit their results.

At a glance

  • Extension point Search filter behavior (or no code at all)
  • You need A saved search with Case Number, District Council and District Council Name filters; the Create/Share Saved Searches permission
  • Teaches Working without context.usergroups, clearing a hidden filter, exact matching of similar filter names

The query panel does not know the user's groups

In the search query panel, context holds only username. context.usergroups is undefined, so a script cannot test group membership. The two options below are what works.

Make a copy of the search for each audience and share each copy with its group.

  1. In the Search app Builder, open the search and save a copy for the clerks.
  2. In the clerks' copy, keep District Council. In the other copy, remove it.
  3. Share each copy with the matching group when you save it.

This needs no script, it is the only option that restricts access, and it keeps working when people join or leave a group.

Option 2: a script with a list of user names

Use this only for a short, stable list. You must edit the script each time someone joins or leaves.

Set it up

  1. In the Builder, open the search and select Case Number, a filter that is always present.
  2. Select Customize Filter > Behaviors > Custom Behavior > Not Configured.
  3. Name it Clerk filters, paste the script below, select Test, then Save & Close. Save the search.

The panel load runs every behavior, so the script runs when the search opens.

Script

Search filter behavior on Case Number
// Attach to: Case Number
// Reads: context.username, District Council. Writes: visibility and value of District Council.
var clerks = ["jsmith@example.org", "alee@example.org"];
var me = (context.username || "").toLowerCase();
var isClerk = clerks.indexOf(me) !== -1;

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

if (!isClerk && (panel["District Council"].Value || "") !== "") {
    // A hidden filter still filters. Clear it so it does not limit the results.
    builder.SetFilterValue("District Council", "");
}

How it works

  • The list holds clerk user names in lowercase. The script lowercases context.username before it compares.
  • SetFilterIsVisible shows the filter only to clerks.
  • A hidden filter's value still goes into the query, so the script clears it for everyone else.
  • "District Council" and "District Council Name" are matched as whole strings, so only the first one hides.

Test it

  1. In the editor, select Test while your own name is not in the list. District Council disappears from the preview. District Council Name stays.
  2. Add your name to the list and select Test again. District Council appears.
  3. Save, then open the search as a clerk and as another user.

You are done when only the listed users see District Council, and other users' results are not limited by it.

What can go wrong

Watch out

  • Nothing hides. The filter name is not one exact quoted string, or its case differs from the Builder.
  • Results are still limited for other users. The script hides the filter but does not clear it. A hidden filter's value stays in the query.
  • A user who left the team still sees the filter. The list is in the script. Edit it, or use Option 1.
  • Hiding is not access control. The script runs in the browser. Anyone who can open the search can run it with any filter value. Use Option 1 and repository permissions to restrict data.