↓ Skip to main content
An isometric drawing of a storage floor with six orange shelves in two rows. Three shelves hold one teal box each and three are empty. An orange hand cart with a teal box rolls along a dotted arrow toward an empty shelf. Three more teal boxes wait beside a gate.

Loading and Displaying Data

You declare a datasource, and the records appear on the page. Most of the time that is the whole story. It stops being the whole story on the day a datasource stays empty and nothing tells you why. We put six datasources on one page and read every request. Four of them loaded when the page opened. Two sent nothing until our code asked.

MAS 9.2 series tutorial

This tutorial walks through the six cases in the order you meet them in an app. It builds on Datasource Basics. We ran every step on our test system, on the MAS 9.2 series, on a page of our Components Explorer. All six datasources read work orders through the object structure mxapiwodetail.

Four phone frames of the page “Data: when a datasource loads”. First, the top of the page: a datasource bound to a list, with its state line and the first work orders. Second, the sections for a datasource bound to nothing and one behind can-load, both with hasData false and 0 rows. Third, the same sections after loadIfNecessary: the unbound datasource now holds 3 rows of 1483, and the gate reads open while its datasource still holds 0 rows. Fourth, the sections for pre-load with 3 rows, for a query that finds nothing, and for one record with the fields 1221, HVAC overheating and Approved.
Six datasources on one page: what loads when the page opens, and what waits

Step 1 · Bind a list, and the datasource loads
#

The usual case needs no code at all. A list names a datasource, and the datasource loads when the page draws the list:

<maximo-datasource id="fs_d_load_bound" object-structure="mxapiwodetail"
    where="siteid=&quot;BEDFORD&quot;" order-by="wonum" page-size="3" selection-mode="none">
  <schema id="fs_d_load_bound_s">
    <attribute name="wonum" unique-id="true" id="fs_d_load_bound_a_wonum"/>
    <attribute name="description" id="fs_d_load_bound_a_description"/>
  </schema>
</maximo-datasource>

<data-list id="fs_d_load_bound_list" datasource="fs_d_load_bound" no-select-behavior="true" show-search="false">
  <list-item id="fs_d_load_bound_list_item">
    <label id="fs_d_load_bound_list_item_t" wrap="true" label="{item.wonum} · {item.description}"/>
  </list-item>
</data-list>

When the page opened, this datasource sent one request, with the where clause, the order and the two attributes of its schema. The answer counted 1,483 work orders. The request asked for six rows, and page-size says three. Pagination and Performance explains why.

Step 2 · Know which datasources stay silent
#

The second datasource of the page has the same declaration, and no list or field reads it. It sent no request when the page opened. Its state read hasData = false with 0 rows.

One detail is worth knowing here. Our page shows the state of every datasource in a label:

<label id="fs_d_load_free_state" label="rows = {fs_d_load_free.state.itemCount} · totalCount = {fs_d_load_free.state.totalCount}"/>

That label reads the datasource, and the datasource stayed silent all the same. On our page a binding to state started no load. A list did, and so did a field that binds to item.

So when a datasource stays empty, look first for the component that reads its records. A datasource that only your controller uses has no such component, and the next step is for that case.

Step 3 · Load from code
#

A controller gets the datasource by its id and loads it:

const ds = this.page.findDatasource('fs_d_load_free');
await ds.load();

Four calls load a datasource, and they differ in when they ask Maximo. We ran each one and counted the requests:

CallOn a datasource that is loaded
load()0 requests, it keeps the rows it has
loadIfNecessary()0 requests, returns false
load({noCache: true})asks Maximo again
forceReload()asks Maximo again

On a datasource that held no rows yet, load() and loadIfNecessary() each sent one request, and loadIfNecessary() returned true.

load() on a loaded datasource is cheap, so a page can call it every time it opens. To see a change that happened on the server, use forceReload().

loadIfNecessary() starts the load and returns at once. Our line read 0 rows at that moment, and the state of the datasource showed 3 rows a moment later. Use await ds.load() when the next line of your code needs the rows.

Step 4 · Hold a datasource back with can-load
#

Some datasources should wait, for example until the user picked a site. The attribute can-load takes a condition:

<state id="fs_d_load_go" name="go" type="boolean" value="false"/>

<maximo-datasource id="fs_d_load_gate" object-structure="mxapiwodetail"
    where="siteid=&quot;BEDFORD&quot;" order-by="description" page-size="3"
    can-load="{page.state.go}" selection-mode="none">

This datasource is bound to a list, as in Step 1. With the condition false it sent no request when the page opened. A load() from code sent none either: the call came back with 0 rows and without an error.

Then we set the state to true and waited, and no request went out. Opening the gate allows the load, and it starts none. The next load() sent the request:

this.page.state.go = true;
await this.page.findDatasource('fs_d_load_gate').load();

Set the condition and call load() together, in the same handler.

Step 5 · Load early with pre-load
#

The opposite wish also exists: a datasource that no component reads, and whose rows your code wants to find loaded. pre-load="true" does that:

<maximo-datasource id="fs_d_load_pre" object-structure="mxapiwodetail"
    where="siteid=&quot;BEDFORD&quot;" order-by="description desc" page-size="3"
    pre-load="true" selection-mode="none">

This datasource is bound to nothing, like the one of Step 2. It sent its request when the page opened and held 3 rows of 1,483.

Step 6 · Show one record
#

A detail page reads one record. The datasource narrows the where clause to that record and sets page-size="1", and fields bind to item, the current record:

<maximo-datasource id="fs_d_load_one" object-structure="mxapiwodetail"
    where="wonum=&quot;1221&quot; and siteid=&quot;BEDFORD&quot;" page-size="1" selection-mode="none">
  <schema id="fs_d_load_one_s">
    <attribute name="wonum" unique-id="true" id="fs_d_load_one_a_wonum"/>
    <attribute name="description" id="fs_d_load_one_a_description"/>
    <attribute name="status" id="fs_d_load_one_a_status"/>
    <attribute name="status_description" id="fs_d_load_one_a_status_description"/>
    <attribute name="wopriority" id="fs_d_load_one_a_wopriority"/>
  </schema>
</maximo-datasource>

<field id="fs_d_load_one_f_num" label="Work order" value="{fs_d_load_one.item.wonum}"/>
<field id="fs_d_load_one_f_status" label="Status" value="{fs_d_load_one.item.status_description}"/>

The fields loaded the datasource when the page opened, with oslc.pageSize=1 in the request.

We made one mistake on the way, and it is a common one. Our first schema had status_description and left out status. The status field then drew a striped bar where its value belongs. With status in the schema it read “Approved”. The cookbook recipe Add a Field shows that bar and what it means.

Step 7 · Tell “nothing yet” from “nothing found”
#

The fifth datasource of the page asks for a work order number that does not exist. It loaded, and Maximo answered with no rows. On screen its list read “No results found”.

The list of Step 4, behind its closed gate, read “No results found” too. Its datasource had never asked. The two lists look the same, and the state of the datasource tells them apart:

hasDataitemCounttotalCount
never loadedfalse00
loaded, and the query found nothingtrue00
loadedtruethe rows it holdsthe rows that match in Maximo

The fourth property is loading. It is true while a request runs, and a label or a loading indicator can bind to it like to any other state. On another page of the explorer we saw it read true while a request for 500 rows with forty attributes ran.

The whole page in the editor
#

Our MAF editor shows these states for every datasource of a page in its Data tab. For this page it lists four datasources as loaded, each with its query and its request. The empty one is marked with 0 rows and the note “no rows for this user”. The two silent datasources of Step 2 and Step 4 are in the group “not loaded” below.

The Data tab of the MAF editor for the page fs_d_load. It lists fs_d_load_bound as loaded with 6 rows of 1483, fs_d_load_pre as loaded with 3 rows of 1483, fs_d_load_none as loaded with 0 rows and the note “no rows for this user”, and fs_d_load_one as loaded with 1 row. Each entry shows its where clause, its select list and its request GET /maximo/oslc/os/mxapiwodetail with status 200.
The datasources of the page with their live state, in the Data tab of our MAF editor

What to read next#

Search and Filtering continues with the calls that change what a loaded datasource shows. Maximo-Datasource vs. JSON-Datasource compares the datasource of this page with the one that reads a file of the app.


IBM documents can-load, pre-load and the other attributes of <maximo-datasource> in the product itself. In the Application Configuration application, open the ? menu and choose Component Documentation.