Skip to main contentMAF Configuration Practices

Client Side Data Source Filtering

About this task

There are multiple ways to filter a data source and in this guide we will focus on applying an in memory filter to the data source. Why might you want to use an in memory filter instead of more traditional filtering through QBE, saved query or where clause? You may want to use an in memory filter when the data that needs to be queried is too complex to be written as a saved-query or when the data needs to be filtered down through multiple relationship levels. This is in memory filter is especially useful when the need to filter multi level attribute information on the mobile device.

This guide will cover an example use case where we would like to provide a list of workorders where the signed in user has an active timer. This example is based off of the TECHMOBILE application.

Procedure

Step 1: Define a new datasource to hold work orders that contain an active timer labor record against the signed in user.

In this example we will be extending the existing work order data source “dswolist” by appending a “maximo-datasource-override” element.

<maximo-datasource-override id="myActiveTimers" saved-query="ASSIGNEDWOLIST" mobile-qbe-filter="{{'status_maxvalue': '!=COMP,CAN,CLOSE,WAPPR', 'assignment[0].status_maxvalue' : '!=WAITASGN'}}" controller="MyActiveTimerDataController"/>

Step 2: Add a new drop down option to the list of saved queries from the work order list.

You can search for the drop down element by searching on the id. Search on value “rzvz4”. Append the additional dropdown-item element.

<dropdown-item value="myActiveTimers" text="My Active Work Orders" id="k3ry_"/>

Step 3: Declare a controller to bind to the “myActiveTimers” data source.

The in memory filter can be defined on various stages of the data source life cycle. In our example we bind to the “onBeforeLoadData” event to apply our filter logic.
Our filter will sort through the various workorders that contain labor transactions. If the work order contains a list of labor transactions than we must check if any of the labor transactions are associated to the signed in user and that the labor record has a timer status of ACTIVE. Note The filter function that you are defining must return either true or false for each item. Returning true will include that item in the datasource while false will not.

class MyActiveTimerDataController {
onDatasourceInitialized(ds, owner, app) {
this.datasource = ds;
this.owner = owner;
this.app = app;
}
onBeforeLoadData(ds, query) {