MAS 9.2 series framework 3.2.8xx three kinds
This follows Understanding app.xml and Pages and Navigation. Those two cover where a datasource is declared and which screen it serves. This post covers what the thing itself is, which of the three kinds to reach for, and what the schema underneath it does. Querying, scope and the lifecycle each have their own post later in this level, and this one hands off to them by name.
The patterns come from the apps that IBM ships with a 9.2-series install. The demonstrations run in our Components Explorer, a small Maximo Mobile app we built for these articles, in the preview of our MAF editor, against the demo data of our test system. Details move with each release, and the shape holds.
What a datasource is#
A datasource is one idea with two halves. In your markup it is a declaration that names a source of data and lists the fields you want from it. At runtime it is a live object that holds those records, tracks which one is current, remembers what the user changed, and knows how to save.
Between those halves sits the part that makes the framework worth using. Your UI components bind to the datasource and read its state, so a list redraws when the data loads and a field shows an error when a save fails. You configure that behaviour and the framework runs it.
One datasource owns a lot of jobs at once:
- Loading records from Maximo, from a local array, or from an adapter you supply
- Paging through a result set that is larger than one screen
- Filtering and searching, including the filter chips a user taps
- Selection, in single, multiple or no-selection mode
- Change tracking, so the framework knows what is dirty and can warn before you leave
- Saving, including the queue that holds a change while a device is offline
The shipped apps lean on all of it. Every app declares many datasources, and a typical app on either build target declares dozens of them. This makes the datasource a framework concept before it is a mobile one.
The three kinds#
Three elements declare a datasource, and the one you pick is decided entirely by what sits behind the data.
Across every datasource element in the apps of the 9.2 series.
| Element | What backs it | Reach for it when |
|---|---|---|
<maximo-datasource> | the Maximo REST API, through an object structure | the data is a Maximo record |
<json-datasource> | a JavaScript array in the browser | the data is yours, built or fetched by your own code |
<custom-datasource> | a data adapter class you write | the data comes from somewhere the framework has never heard of |
The client-side one is everywhere#
The <json-datasource> appears in about as many apps as the Maximo one. The kind that looks like a helper reaches as far as the kind everyone learns first.
The reason is that a lot of what fills a screen was never a Maximo record. A JSON datasource holds the markers on a map, the items in a submenu, a picklist assembled from three server calls, or the response from a service that answers in its own shape. All of it needs paging, selection and binding, so all of it wants a datasource.
Most of them start out empty. They declare src="{[]}", which is an empty array that a controller fills at runtime.
<json-datasource id="fitReadingsDS" src="{[]}" id-attribute="_id" selection-mode="single"/>That one line is the whole declaration, and only id-attribute needs explaining. It tells the datasource which field identifies a row, and _id is the framework’s own generated key for objects that arrived without one.
The Maximo one, and the object structure behind it#
A <maximo-datasource> names an object structure, which is the server-side view that decides what is reachable at all. The corpus references many distinct ones, mxapiasset most often.
<maximo-datasource id="fitPumpDS"
object-structure="mxapiasset"
order-by="assetnum"
page-size="20"
selection-mode="single">
<schema id="fit_pump_schema">
<attribute name="assetnum" unique-id="true" searchable="true" id="fit_pumpnum"/>
<attribute name="description" searchable="true" id="fit_pumpdesc"/>
<attribute name="status" id="fit_pumpstatus"/>
</schema>
</maximo-datasource>Everything except id and the object structure is optional, and the defaults are reasonable. Most of the shipped Maximo datasources set selection-mode. Some also set order-by or page-size, and the rest leave them at the default.
The custom one, and the override#
<custom-datasource> takes a data-adapter you write, so the framework handles binding, paging and selection while your class decides where the bytes come from. Only a few apps use it, and it is the right answer for a non-Maximo backend that still deserves a real list on screen.
There is also a fourth shape worth recognising when you meet it. A <maximo-datasource-override> sits inside another datasource and reuses its schema while changing a few settings, most often the selection mode. Several apps use them, and they exist so a filter panel can offer multiple selection over exactly the data the list already fetched.
One object with one API, and three different things behind it.
The schema is a shopping list#
This is the part that costs people an afternoon, so it is worth stating plainly. The <schema> block inside a Maximo datasource is a list of the attributes you want fetched. It describes your request and it never describes the record.
An object structure can expose hundreds of attributes. What a real datasource asks for is much smaller.
Read across the shipped apps, the pattern is the same everywhere.
- Most Maximo datasources fetch only a handful of attributes: a key, a description, a status and whatever the screen shows.
- The big ones are the detail screens of the big apps, where a single record drives a whole page.
Two consequences follow, and both of them look like bugs when you meet them.
An attribute you did not declare is simply absent. The server was never asked for it, so the field arrives empty and nothing at all is logged. A binding to an undeclared attribute renders blank, which the MAML Basics post names as the most common reason for an empty field on screen.
A bigger schema is a slower screen. Every attribute is more to fetch, more to hold, and on a device more to store and to sync. The reason a typical schema stays small is that the shipped apps ask for what they display.
So the useful habit is to write the schema from the screen. List the fields the page actually shows, add the key and whatever you sort or search on, and stop there. Start narrow, and widen it when something turns out to be missing.
One attribute in the fragment above carries a flag worth knowing early. unique-id="true" marks the attribute that identifies a row, and the framework needs it to track selection and changes. Some shipped datasources also set id-attribute on the element itself, which does the same job from the outside.
Parents and children#
Datasources come in families, and that family is how a detail page loads its related lists without any code at all.
A child datasource is declared inside its parent and points at a Maximo relationship. When the child loads, it follows that relationship from the parent’s current record. A sizeable part of the datasources in the corpus are nested this way, in most of the apps.
<maximo-datasource id="fitPumpDS" object-structure="mxapiasset">
<schema id="fit_pump_schema">
<attribute name="assetnum" unique-id="true" id="fit_pumpnum"/>
</schema>
<maximo-datasource id="fitMeterDS"
object-name="assetmeter"
relationship="assetmeter"
depends-on="fitPumpDS"
selection-mode="none">
<schema id="fit_meter_schema">
<attribute name="assetmeterid" unique-id="true" id="fit_meterid"/>
<attribute name="metername" id="fit_metername"/>
<attribute name="lastreading" id="fit_lastreading"/>
</schema>
</maximo-datasource>
</maximo-datasource>Two attributes do the work: relationship names the Maximo relationship to follow, and depends-on names the parent to follow it from. The child needs no object structure, because it reaches its data through the parent. It still needs a unique-id attribute of its own, and the build warns when it is missing.
On a detail page that is all it takes, because the parent holds one record and the child loads for it. On a page that lists the parents, a second step is needed. We put four pumps from the asset object structure in a list, with a child of the same shape underneath it. The heading of the meter list binds the parent’s current record.
- The page opens. The child loads by itself for the first pump and shows its two meters.
- A button calls
setCurrentItemon the parent for pump 11470. The heading follows at once, and the list still shows the two meters of the first pump. A call tosetSelectedItemchanges nothing in the list either. - A button calls
setCurrentItemand thenload()on the child. The list shows the one meter of 11470.

So the handler that changes the current record also loads the child:
async showMeters(pump) {
const pumps = this.page.findDatasource("fitPumpDS");
pumps.setCurrentItem(pump);
await this.page.findDatasource("fitMeterDS").load();
}Reaching one from a controller#
Everything above is declaration, and when you need the live object one call gets it. The shipped controllers use this route all the time, and findDatasource turns up in almost every app.
async loadPumps() {
const ds = this.app.findDatasource("fitPumpDS");
await ds.load();
return ds.items.length;
}From there the object gives you items for what is loaded, item for the current record, and state for everything the UI is binding to, including loading, itemCount and the current selection. Items are exposed as getters, so ds.items reads the array directly and there is no accessor method to call.
Our MAF editor shows these live objects in its Data tab. For the pump page it lists both datasources with the rows each one holds, the current row, the query the datasource built and the request that went to the server. The code of the page stands beside it, so the declaration and the live object are on one screen.

What this post leaves to the others#
Four questions come up immediately and each belongs to its own post later in this level.
- How do I filter it? Saved Queries and Filters covers saved queries, where clauses and query by example. The short version is that
saved-querypoints at a server-side query andwherecarries a clause you wrote. - Where should I declare it? App level, page level and dialog level behave differently, and App vs Page vs Datasource Scope covers that.
- When exactly does it load? The events, their order and what is safe to do in each belong to a deeper post on the datasource lifecycle.
- What changes on a device? Offline download, the local database and the transaction queue belong to the runtime level.
What to read next#
Datasources are the supply and the pages are the demand. For where these declarations sit, read Understanding app.xml. For the screens they feed, read Pages and Navigation. For the whole application as one object, read Anatomy of a Maximo Mobile App.
IBM’s own reference for <maximo-datasource>, <json-datasource> and the schema elements ships with every MAS install. In the Application Configuration application, open the ? menu and choose Component Documentation.
