↓ Skip to main content
A gouache painting of a wooden workbench with two open crates. The left crate is teal and holds four folded teal cloths, and a teal rope tied to it runs out of the picture to the left. A hand from above holds a fifth teal cloth over it. The right crate is orange, stands alone and holds four folded orange cloths.

Maximo-Datasource vs. JSON-Datasource

A page can take its rows from Maximo or from a file of the app. The markup of the two looks almost the same, and so does the list on screen. We put both kinds on one page and ran the same seven calls on each. One kind sent a request for almost every call. The other kind sent none.

MAS 9.2 series comparison

This post builds on Datasource Basics, which explains what a datasource is and names the three kinds. Here we compare the two you use every day. We ran every call on our test system, on the MAS 9.2 series, on a page of our Components Explorer, a small Maximo Mobile app we built for these articles.

The same list, twice
#

The first datasource reads the work orders of one site from Maximo:

<maximo-datasource id="fs_d_kinds_mx" object-structure="mxapiwodetail"
    where="siteid=&quot;BEDFORD&quot;" order-by="wonum" page-size="5" selection-mode="none">
  <schema id="fs_d_kinds_mx_s">
    <attribute name="wonum" unique-id="true" id="fs_d_kinds_mx_a_wonum"/>
    <attribute name="description" searchable="true" id="fs_d_kinds_mx_a_description"/>
    <attribute name="status" id="fs_d_kinds_mx_a_status"/>
    <attribute name="wopriority" id="fs_d_kinds_mx_a_wopriority"/>
  </schema>
</maximo-datasource>

The second one reads ten demo work orders from a file of the app:

<json-datasource id="fs_d_kinds_js" src="fs-workorders.js" id-attribute="_id"
    pre-load="true" page-size="5" selection-mode="none">
  <schema id="fs_d_kinds_js_s">
    <attribute id="fs_d_kinds_js_a_wonum" name="wonum" type="STRING" unique-id="true"/>
    <attribute id="fs_d_kinds_js_a_description" name="description" type="STRING" searchable="true"/>
    <attribute id="fs_d_kinds_js_a_status" name="status" type="STRING"/>
    <attribute id="fs_d_kinds_js_a_wopriority" name="wopriority" type="NUMBER"/>
  </schema>
</json-datasource>

The file exports an array of plain objects, one per row. Two of the ten rows, shortened here:

const workorders = [
  {_id: 1, wonum: 'WO-1001', description: 'Replace pump seal', status: 'WAPPR', wopriority: 1},
  {_id: 2, wonum: 'WO-1002', description: 'Monthly compressor check', status: 'APPR', wopriority: 3}
];
export default workorders;

Three things differ in the declaration:

maximo-datasourcejson-datasource
Where the rows come fromobject-structure, with where and order-bysrc, a file of the app
The key of a rowthe attribute with unique-idid-attribute names a property of the row
The type of an attributeour schema names nonetype on each attribute

Everything that reads the rows is the same for both. A data-list names the datasource, and a label binds to {item.wonum}. The page shows one list under the other:

Three phone frames of the page “Data: two kinds of datasource”. Left, the top of the page after a search for pump on the Maximo datasource: the line “Last call: search(“pump”) on fs_d_kinds_mx: 5 rows of 46” and the state line with totalCount 46, above the buttons search, qbe, edit and save. Middle, the list of the Maximo datasource with work orders such as 1002 Rebuild Feedwater Pump. Right, the heading of the json-datasource after the same search, with the state line rows 3 and totalCount 3.
One page, two kinds of datasource, and the same search on each

What each one sends
#

When the page opens, the Maximo datasource sends one request. We read it in the browser:

GET …/oslc/os/mxapiwodetail
    oslc.select=wonum,description,status,wopriority
    oslc.where=siteid="BEDFORD"
    oslc.orderBy=+wonum
    oslc.pageSize=10
    collectioncount=1

Each part comes from the declaration. The select is the schema, and the where clause and the order are the attributes of the same name. The answer said that 1,483 work orders match, and on a phone the list drew the first five. The request asks for ten rows, and the datasource says five. Pagination and Performance explains that.

The JSON datasource sent nothing. Its ten rows travel inside the app, and the list drew five of them, because page-size counts for both kinds.

Then we ran the same seven calls on each datasource and counted the requests:

Callmaximo-datasourcejson-datasource
the page opens1 request, 5 rows of 1,4830 requests, 5 rows of 10
search("pump")1 request with oslc.searchTerms=pump, 46 work orders0 requests, 3 rows
search("")1 request, 1,483 again0 requests, 10 again
a filter on status = APPR1 request, the where clause gains and status="APPR", 318 work orders0 requests, 3 rows
change the priority of the first row0 requests0 requests
save()1 request to the record0 requests
forceReload()1 request0 requests

Search and filters work on both
#

The controller code is the same for both kinds. One method of our page takes the id of a datasource and runs the call on it:

const ds = this.page.findDatasource(id);
await ds.search('pump');

ds.setQBE('status', '=', 'APPR');
await ds.searchQBE();

The place where the work happens differs. Maximo searched all 1,483 work orders of the site and returned the 46 that match. The JSON datasource searched its ten rows in the memory of the app and kept three. Both looked into the attributes the schema marks with searchable="true".

So a JSON datasource is a full datasource for a list: it pages, it searches, it filters, and a data-list with a search box works on it. Search and Filtering goes through these calls one by one.

Saving is where the two part
#

We changed the priority of the first row in both lists and called save().

On the Maximo datasource the change set the state itemsChanged to true and sent nothing. The save sent one request to the record. After it, a read through the API showed the new priority on the server, changed by the user of our API key.

On the JSON datasource the change set itemsChanged too. The save sent nothing and reported no error. The new value stayed in the memory of the app: a forceReload() kept it, and a reload of the app in the browser brought back the value of the file.

A JSON datasource therefore holds a change only while the app runs. Data that a user expects to find again tomorrow, or that a colleague has to see, belongs in a Maximo datasource.

What the editor shows
#

Our MAF editor lists the live datasources of a page in its Data tab. For this page it shows the difference in two entries. The Maximo datasource comes with its query and the request it sent. The JSON one comes with a line that says it reads no object structure.

The Data tab of the MAF editor for the page fs_d_kinds. First entry: fs_d_kinds_mx, loaded, 5 rows of 1483, its query with the where clause siteid BEDFORD and the select list wonum, description, status, wopriority, and its request GET /maximo/oslc/os/mxapiwodetail with status 200. Second entry: fs_d_kinds_js, loaded, 5 rows of 10, with the line “no request: this datasource reads no object structure”. Below it, “107 datasources not loaded”.
Both datasources of the page in the Data tab of our MAF editor

Which one to use
#

You needUse
records of Maximo: work orders, assets, locationsmaximo-datasource
data the user changes and expects to keepmaximo-datasource
a short fixed list: the choices of a filter, the entries of a menujson-datasource with a file
rows that your code builds at runtimejson-datasource, filled by a controller
a page that has to draw without any server, for a demo or a testjson-datasource with a file

The fourth row is a common pattern in the apps IBM ships: a JSON datasource starts with an empty array as its source, src="{[]}", and a controller fills it, for example with the markers of a map.

The third kind, the datasource with an adapter of your own, is for data from a system other than Maximo. Datasource Basics introduces it.

What to read next#

Loading and Displaying Data shows when a datasource sends its first request, and which datasources of a page send none. The cookbook recipe Add a Field shows what the schema does to the request, one attribute at a time.


IBM’s own reference for <maximo-datasource> and <json-datasource> ships with every MAS install. In the Application Configuration application, open the ? menu and choose Component Documentation.