↓ Skip to main content
A folk art painting of a card catalogue cabinet with twelve drawers in three rows of four. Eleven drawers are teal and closed. One drawer in the middle row is orange and pulled open, with a row of cards in it.

Datasource Cheatsheet

A datasource has few parts, and each part has a surprise or two. This page lists the parts with the behaviour we measured: what a declaration needs, what a call sends, and which state to read afterwards. Keep it open while you work, and follow a link when a line needs its reasons.

MAS 9.2 series cheatsheet

Every count of requests on this page is measured on our test system, on the MAS 9.2 series, in the browser preview of our Components Explorer. The examples read work orders through the object structure mxapiwodetail.

The declaration
#

<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>
AttributeWhat it doesWorth knowing
object-structurethe object structure the rows come froma wrong name answers with HTTP 404
wheretravels as oslc.wherequotes are written as &quot;; a wrong attribute answers with HTTP 400
saved-querya saved query of the object structurecombines with where: the rows are those that both allow; an administrator can change it without a new build
order-bytravels as oslc.orderByorder-by="wonum" sends +wonum
page-sizethe rows of a pagethe sizes 3, 5, 10 and 20 asked Maximo for twice the number
can-loada condition that holds the datasource backsetting it to true starts no load; call load()
pre-load="true"loads when the page opens, with no component reading itfor rows that only your code uses
include-counts="false"drops collectioncount=1 from the requestno difference in time that we could measure
controllera class for the hooks of this datasourcegets each hook before the page controller
selection-modenone, single or multiple

A json-datasource reads a file of the app. It names the file with src and its key with id-attribute, and it sends no request for any call in the tables of this page.

The guides for this section are Loading and Displaying Data, Maximo-Datasource vs. JSON-Datasource, Saved Queries and Filters.

The schema
#

The schema is the select list of the request. An attribute that a binding reads has to be in it.

In the schemaIn the requestIn the row
descriptiondescriptionitem.description
asset.descriptionasset.descriptionitem.asset.description
asset.description--assetdescasset.description--assetdescitem.assetdesc
rel.woactivity{taskid,description}rel.woactivity{taskid,description}item.woactivity, a list
computedLine with computed-functionnothingitem.computedLine
  • A misspelled attribute passes the build. Maximo answers 200 and leaves the name out.
  • A status needs status and status_description.
  • searchable="true" puts an attribute into the text search.
  • A computed function runs more often than once per row. Keep it fast and free of side effects.
  • A schema with 40 attributes gave an answer two and a half times as large as one with 4.

The guide for this section is the schema guide.

When it loads
#

The datasource isFirst request
bound to a list, or to a field through itemwhen the page draws
bound to nothingnone, until code calls load()
bound only through state, as in a label for its countnone
behind can-load that is falsenone, also for load()
marked with pre-load="true"when the page opens

The states
#

Bind to them with {myDatasource.state.loading}.

StateMeaning
loadingtrue while a request runs
hasDatafalse until the first load; true after a load, also when it found nothing
itemCountthe rows the datasource holds
totalCountthe rows that match in Maximo
itemsChangedtrue while a change is unsaved
pageSizethe page size in use
currentSearchthe text of the last search

An empty list reads “No results found” for a datasource that never loaded and for a query that found nothing. hasData tells the two apart.

Reading
#

const ds = this.page.findDatasource('fs_d_load_free');
await ds.load();
CallRequests on a loaded datasourceNote
load()0keeps the rows it has
loadIfNecessary()0returns at once, with true when it started a load
load({noCache: true})1
forceReload()1the call to see a change of the server
loadRange(ds.items.length, 20)0 or 1takes the reserve first, then asks for the next page
updatePageSize(100), then forceReload()1the request asks for the new size

A list that scrolls to its end loads the next rows by itself. One request serves two screens of rows.

The guide for this section is Pagination and Performance.

Searching and filtering
#

CallRunsSends
search('pump')in Maximooslc.searchTerms=pump over the searchable attributes
search('pump', ['description'])in Maximothe same, over the named attributes
search('')in Maximothe request without a search text
setQBE('status', '=', 'APPR')nowhere yetnothing, it only stages the filter
searchQBE()in Maximothe staged filters inside oslc.where
clearQBE(), then searchQBE()in Maximothe request without the filters
applyInMemoryFilter((item) => …)in the appnothing; it sees the loaded rows only
search('pump', undefined, true)in the appnothing; it sees the loaded rows only
clearInMemoryFilter()in the appnothing; it also undoes a search in memory
  • A search and a filter by column combine in one request.
  • A second search with the same text sends nothing, also when its list of attributes differs.
  • search('') does not undo a search in memory.
  • In a list, the search box sends its request on the Enter key.
  • For the signed-in user, oslc.where knows "-userid-", "-personid-" and "-laborcode-". &USERNAME& matched no row.

The guide for this section is Search and Filtering.

Changing and saving
#

ds.items[0].wopriority = 3;
const result = await ds.save();
if (result && result.error) {
  return; // unsaved, and the user has seen the message
}
CallRequestsWhat happens
a changed value0itemsChanged turns true, onValueChanged runs
save() with a change1a POST to the record with x-method-override: PATCH; the body has the changed attribute and three technical keys
save() without a change0returns at once
undoAll()0takes back every unsaved change
  • A refused save does not throw. save() returns an object with error, and the framework shows the message of Maximo in a dialog.
  • After a refused save the wrong value is still in the record, and itemsChanged is still true.
  • A save over a record that another user changed goes through. Maximo merges by attribute, and for the same attribute the last save wins.
  • On a json-datasource, save() sends nothing, and the value lasts until the app reloads.

The guide for this section is Saving and Updating Data.

The hooks of a datasource controller
#

HookRuns
onDatasourceInitialized(ds)once, when the page of the datasource first opens
onBeforeLoadData(ds)before every load
onAfterLoadData(ds, items)after every load, with the rows
onValueChangedfor every changed value, also for values that a save brings back
onBeforeSaveDatabefore the request of a save
onAfterSaveDataafter the answer of a save
onSaveDataFailedwhen Maximo refuses a save

A hook of a datasource also reaches the page controller and the application controller, when they have a method of the same name.

The guides for this section are Using Lifecycle Hooks Correctly, Controller Architecture Overview.

This page as a PDF, to print or to keep beside the keyboard.


IBM documents <maximo-datasource>, <json-datasource>, <schema> and <attribute> in the product itself. In the Application Configuration application, open the ? menu and choose Component Documentation.