↓ Skip to main content
Four stacked paper sieves of decreasing mesh, with twelve small shapes entering the top and three reaching the dish below

Saved Queries and Filters

Your datasource works and it returns forty thousand records. Five separate things can narrow that, and each runs somewhere different. On the server, in your markup, in a child declaration, on the device, and in a controller at the moment a user taps a chip. Picking the wrong layer is the difference between an administrator fixing a filter in an afternoon and you shipping a new build.

MAS 9.2 series framework 3.2.8xx five layers

This follows Datasource Basics, which named filtering as a handoff and stopped there. The post covers which mechanism to pick and where each one runs. The full operator table belongs to the query syntax reference later in this level, so the comparison forms are shown by example here.

The patterns come from the apps that IBM ships with a 9.2-series install. The demonstration runs in our Components Explorer, a small Maximo Mobile app we built for these articles, in the preview of our MAF editor. Details move with each release, and the shape holds.

The five layers
#

They stack, and a record has to survive every layer above it to reach the screen.

Across the Maximo datasources in the apps of the 9.2 series.

LayerDeclared inRunsChanged by
saved querysaved-query on the datasourcethe server, on every fetchan administrator, in Maximo
where clausewhere on the datasourcethe server, on every fetcha developer, in the app
overridea nested <maximo-datasource-override>the server, for that viewa developer, in the app
offline filtermobile-qbe-filterthe device, against local dataa developer, in the app
query by examplesetQBE then searchQBE in a controllerwherever the datasource readsthe user, at runtime

The column that matters most is the last one, which says who can change the filter later. A saved query lives on the Maximo server, so an administrator can change what the app shows without anybody rebuilding or republishing it. Every other layer is baked into the app and needs a new build to change.

Mobile and web choose opposite defaults
#

Here is the finding, and the split is sharper than we expected it to be.

The same reading, split by build target.

mobile appsweb apps
saved-querycommonrare
whererarecommon

A mobile datasource reaches for a server-side saved query far more often than for a where clause. A web datasource does the reverse and prefers a where clause. The two targets share a framework and disagree about how to filter.

The reason is the offline download. A mobile app pulls its records onto the device ahead of time, so what the server sends is what the technician has all day. The size of that download is the difference between a fast morning and a slow one. A saved query narrows the set before it ever leaves the server, and an administrator can retune it per site without touching the app. A web app fetches a page at a time over a live connection, so a clause written in the markup costs nothing to change at the next release.

Some datasources in the corpus carry both, which is legal. The saved query and the where clause are combined, and what comes back is the intersection.

The where clause is usually not a fixed string
#

The second finding is the practical one. A large part of the where clauses in the corpus contain a binding. So they are assembled at runtime out of page or application state.

<maximo-datasource id="fitPumpListDS"
                   object-structure="mxapiasset"
                   where="siteid=&quot;{app.state.currentSite}&quot; and status=&quot;OPERATING&quot;"
                   order-by="assetnum"/>

That expression is evaluated the same way every other binding is, which Data Binding covers. When the bound value changes the datasource reloads against the new clause.

Two things to know before you write one. The clause is Maximo where-clause syntax, so it goes to the server as written and the column names are the ones the object structure exposes. The quoting is also awkward in XML. A string literal needs double quotes inside an attribute that is already delimited by double quotes, which is why the shipped apps are full of &quot;.

The override, for a second view of the same data
#

An override is a datasource that reuses its parent’s schema and changes a few settings. It exists so a filter panel can offer a different selection mode over exactly the data the list already fetched, with no second schema to keep in step.

<maximo-datasource id="fitPumpListDS" object-structure="mxapiasset" saved-query="MOBILEMYASSET">
  <schema id="fit_pump_schema">
    <attribute name="assetnum" unique-id="true" id="fit_pumpnum"/>
    <attribute name="status" id="fit_pumpstatus"/>
  </schema>

  <maximo-datasource-override id="fitFilterDS"
                              selection-mode="multiple"
                              saved-query=""/>
</maximo-datasource>

Overrides in the corpus change a selection mode, carry their own where clause, or, in a few cases, clear the parent’s saved query by setting it to an empty string. That last trick is worth remembering, because an override otherwise inherits the parent’s filter and there is no other way to widen it.

The offline filter, on mobile only
#

mobile-qbe-filter narrows what a device shows from the data it already holds. It appears on only a few datasources, and every one of them is in a mobile app. That is what you would expect from a filter that means something only once the records are local.

<maximo-datasource id="fitPumpListDS"
                   object-structure="mxapiasset"
                   mobile-qbe-filter="{{'status':'!=DECOMMISSIONED'}}"/>

The double brace is the argument-object form from Data Binding, and the value is a set of column filters in the same shape the runtime API uses.

Query by example, at runtime
#

The last layer is the one the user drives. A filter chip, a search box or a dropdown ends in controller code that stages filters and then runs them.

async applyFitFilters(status, site) {
  const ds = this.app.findDatasource("fitPumpListDS");
  ds.setQBE("status", "=", status);
  ds.setQBE("siteid", "=", site);
  await ds.searchQBE();
}

Two calls do the work and the split between them is the point. setQBE stages one column filter and changes nothing on screen, while searchQBE executes whatever has been staged. Filters on different columns combine. A fourth argument, append, matters only when the same column is staged twice: with true the second value is added to that column’s filter, and without it the second value replaces the first.

The corpus shows that shape plainly. The calls to setQBE outnumber the calls to searchQBE, which is what one user action setting three columns and running one search looks like.

In our Components Explorer two buttons each stage one column filter with setQBE, Search runs searchQBE, and Clear calls clearQBE and searches again. The datasource is a JSON datasource of ten demo work orders, and the same calls filter its rows.

  1. Nothing is staged and the list shows 10 rows.
  2. Both filters are staged, status = APPR and worktype = PM. The list still shows 10 rows.
  3. Search runs the staged filters once. The list narrows to 3 rows, the approved preventive work orders.
  4. Clear empties the staged filters and searches again. The list is back to 10 rows.
Four frames of Maximo Mobile at tablet width, on the page “QBE: stage, then search”, with the buttons status = APPR, worktype = PM, Search and Clear above a list of work orders. First, “Staged: nothing” and “Rows: 10”. Second, “Staged: status = APPR, worktype = PM” and still “Rows: 10”. Third, after Search, “Rows: 3” with WO-1002, WO-1005 and WO-1008, each APPR and PM. Fourth, after Clear, “Staged: nothing” and “Rows: 10” again.
setQBE stages, searchQBE runs, clearQBE empties, in Maximo Mobile at tablet width, in the preview of our MAF editor

clearQBE removes the staged filters and is called regularly. Its sibling cancelQBE reverts to the previous filter instead of emptying it, and no shipped app calls it at all. As with every unused feature on this site, that says IBM never used it and says nothing about whether it works.

d2 diagram d2 diagram

Five layers, and a record has to survive all of them.

Which one to reach for
#

The question to ask is who will want this changed, and when.

  • An administrator will retune it per site or per customer. Use a saved query. It is the only layer that changes without a build.
  • It is a rule of your application that never varies. Use a where clause. It sits beside the datasource where the next developer will find it.
  • It depends on who is logged in or where they are. Use a where clause with a binding, which is what most of the corpus does.
  • You need a second view of data you already fetched. Use an override, and remember to clear the parent’s saved query if you are widening.
  • The user decides. Use the runtime calls, staged with setQBE and run with searchQBE.

What to read next#

The layer below this one is the datasource itself, in Datasource Basics. The expressions inside a dynamic where clause are in Data Binding. For the whole application around all of it, read Anatomy of a Maximo Mobile App.


Saved queries are defined in Maximo itself and not in your app, so the list of names available to you is the list an administrator has created on that server. IBM’s own reference for the datasource attributes named here ships with every MAS install, under Component Documentation in the Application Configuration application.