Parsware
All articles

Model-driven apps

Filters with And and Or

Build a filter from conditions in groups, each group either And or Or, and put one group inside another. Use it once while you browse a list, or save it on a view so everyone who opens the view gets it.

The Filter records panel in dark mode: an And group holding "In Service equals Yes" and an Or group of two conditions, next to the title "Filters with And and Or"

"Show me the assets still in service that cost a lot or are old." That sentence has an and and an or in it, and the or only applies to the second half. A filter in Parsware is built the same way: conditions go in groups, each group is either And or Or, and a group can sit inside another group.

We use the Assets table from Views: the lists people work in. Every picture is the real product.

A one-off filter in the app

Open the list and select Filter above it. The panel opens with an empty And group.

  1. Select Add condition. Pick In Service, Equals, Yes.
  2. Select Add group. A second group appears inside the first. Set it to Or.
  3. Inside that group, add two conditions: Purchase Cost Greater than 1500, and Purchase Date Less than 1 January 2024.

The Filter records panel: an And group with In Service equals Yes, and inside it an Or group with Purchase Cost greater than 1500 and Purchase Date less than 01/01/2024

Read it from the outside in: in service, and (expensive or old). An And group needs every condition in it to match. An Or group needs at least one.

Select Apply. The list shows the three assets that match, and a dot on Filter tells you a filter is on:

The Assets list with three rows, MacBook Pro 14", Logitech Rally Bar and ThinkPad X1 Carbon, and a dot on the Filter button

The Surface Laptop and the HP printer are old enough to match the Or group, but they're out of service, so the And leaves them out.

This filter is yours alone: it isn't saved to the view, and nobody else sees it. Clear in the panel removes it.

Which comparisons you get

The comparisons depend on the field:

  • Text: Contains, Equals, Does not equal, Is one of, Is empty, Is not empty.
  • Numbers and dates: Equals, Does not equal, Greater than, Is at least, Less than, Is at most, Is empty, Is not empty. Numbers also get Is one of.
  • Yes/no: Equals, Is empty, Is not empty.
  • Choices: Equals, Does not equal, Is one of, and the two empty ones. The value is picked from the choice's own list.

Is one of takes several values at once, so "status is New or Active" is one condition, not a group of two.

Save it on a view

When the same question comes up every week, save it. Open the view in the View Designer, or create a new one: we made one called Due for Review. Select Filter at the top of the designer and build the same groups:

The View Designer for the new Due for Review view, with its Filter panel open showing the same And group and nested Or group

Select Apply, then Save. The filter is now part of the view. Everyone who opens Due for Review sees only those assets, and it moves with your solution like the view's columns.

The Assets list on the Due for Review view, showing the same three assets

Both at once

A saved filter isn't shown in the Filter panel. The panel opens empty, and anything you add there narrows the view further: the two are combined with And.

On Due for Review, add Purchase Cost Greater than 2000:

The Due for Review list narrowed to two assets, MacBook Pro 14" and Logitech Rally Bar, with the Filter dot on

So a maker decides what a view is about, and each person can narrow it for the task in front of them without changing it for anyone else.

The filter as the view stores it

The groups you built in the panel are saved in the view as one nested structure. Due for Review:

{
  "logicalName": "con_asset_dueforreview",
  "displayName": "Due for Review",
  "entity": "con_asset",
  "columns": ["con_name", "con_purchasedate", "con_purchasecost", "con_assignedto"],
  "filterGroup": {
    "connector": "And",
    "conditions": [
      { "field": "con_inservice", "operator": "Equals", "value": true }
    ],
    "groups": [
      {
        "connector": "Or",
        "conditions": [
          { "field": "con_purchasecost", "operator": "GreaterThan", "value": 1500 },
          { "field": "con_purchasedate", "operator": "LessThan", "value": "2024-01-01" }
        ]
      }
    ]
  }
}

Read it the way you read the panel: the outer group's connector applies to everything directly inside it, its own conditions and its inner groups alike. Is one of stores its values as a list, "operator": "In", "value": [100000002, 100000003], and the two empty comparisons store no value at all.

Patterns worth knowing

Most real filters are one of a handful of shapes. Each is written here as a sentence, then as the groups that say it.

The question The groups
Open invoices over £1,000 And: State equals Active; Amount greater than 1000
Leads from a referral or a conference And: Source is one of Referral, Conference
Work nobody has picked up And: Assigned To is empty
Urgent, or due before Friday Or: Priority equals High; Due date less than the date you choose
In London, and either new or unpaid And: City equals London; Or group: Status equals New; Paid equals No
Everything except cancelled And: Reason does not equal Cancelled

Two of these are worth a second look. Is one of replaces an Or group of Equals conditions on the same field, and is easier to read. And Is empty is often the most useful filter of all: a view of work with no assignee, contacts with no email or assets with no serial number turns a gap in the data into a list somebody can finish.

Lookups in a filter

A lookup field gets Equals, Does not equal, Is one of and the two empty comparisons, with the value picked from a search over the related table. Assigned To is one of Riley Miller, Casey Kim is one condition. Because the filter stores the records' ids, not their names, it keeps working when somebody's name is corrected.

When nothing matches

A filter that returns nothing is usually right about the data and wrong about the question. Check, in this order:

  1. Is a group And where you meant Or? Two conditions on the same field joined by And, such as City equals London and City equals Leeds, can never both be true.
  2. Is a saved filter already narrowing the view? The panel starts empty even on a view with a saved filter, and the two are combined. Switch to a view without one, such as All, and try again.
  3. Is the value what you think? Less than 1 January 2024 leaves out anything bought on that day. Use Is at most when the boundary should count.
  4. Can you see the records at all? Every list is limited to the records your role lets you read before any filter is applied. Record access: whose records you see explains how roles narrow it.

Where else filters are used

The same groups, with the same comparisons, appear wherever the platform asks which records?

Learning the panel once, then, covers all of them.

Saved filter, or a filter of your own?

Save a filter on a view when the same question is asked by several people, or by one person every week, and give the view a name that says what it is. Keep it as a one-off in the app when it is a question for this afternoon. A view list full of one person's afternoon questions is a list nobody else can find anything in.

Questions that come up

How deep can groups go? A group can hold groups, and they can hold groups in turn. In practice two levels say almost everything; if a filter needs more, it is often two questions that deserve two views.

Can a saved filter use the person who opens it, such as my records? The view's filter is the same for everybody. What differs per person is what their role lets them read, which is applied first. For a list of my records, a role scoped to the records a person owns does the work; see Record access.

Is the filter checked when I save the view? Yes. A view is checked against its table when saved, so a condition on a field the table doesn't have is refused, with the field named.

Do filters slow a list down? Filtering happens in the database, before any rows are sent, so a filtered list is usually faster than an unfiltered one. Only the matching rows travel, a page at a time.

Two small things

  • An And group that should have been Or is the usual reason a filter matches nothing.
  • Filtering happens on the server, so only the matching records are sent, and paging works as normal.

While writing this we found that a date condition inside a group showed only its time, because the date box was squeezed. The columns of a condition now share the panel's width, so the whole date fits.

Filters on relative dates, such as "in the last 30 days", aren't built yet. When they are, they'll get their own article.

Next: lookup views and quick find.