MAS 9.2 series tutorial
This tutorial builds on Loading and Displaying Data. We ran every step on our test system, on the MAS 9.2 series, on a page of our Components Explorer, in the browser preview. There every save goes straight to Maximo. On a device, a save first goes into the local queue of the app, and this tutorial does not cover that way.
The page of this tutorial#
The datasource reads one work order. Its schema names the attributes the page shows and changes:
<maximo-datasource id="fs_d_write_mx" object-structure="mxapiwodetail"
where="wonum="1000" and siteid="BEDFORD"" page-size="1"
selection-mode="none" controller="FsSaveDsController">
<schema id="fs_d_write_mx_s">
<attribute name="wonum" unique-id="true" id="fs_d_write_mx_a_wonum"/>
<attribute name="description" id="fs_d_write_mx_a_description"/>
<attribute name="wopriority" id="fs_d_write_mx_a_wopriority"/>
<attribute name="worktype" id="fs_d_write_mx_a_worktype"/>
<attribute name="status" id="fs_d_write_mx_a_status"/>
<attribute name="status_description" id="fs_d_write_mx_a_status_description"/>
<attribute name="changeby" id="fs_d_write_mx_a_changeby"/>
<attribute name="changedate" id="fs_d_write_mx_a_changedate"/>
</schema>
</maximo-datasource>The datasource has a controller of its own. It has a method for every save event, and each method writes its name into a trace on the page.

Step 1 · Change a value#
A value changes in two ways. A field that is bound to the record changes it when the user types:
<text-input id="fs_d_write_in_desc" label="Description, bound to the record"
value="{fs_d_write_mx.item.description}"/>A controller changes it with a plain assignment:
const ds = this.page.findDatasource('fs_d_write_mx');
ds.items[0].wopriority = 3;In both cases the datasource sent no request. Its state itemsChanged turned to true, and its controller got the hook onValueChanged. The field on the page showed the new value at once.
itemsChanged is the state to bind a save button to. It is true as long as there is something to save.
Step 2 · Save#
const result = await ds.save();The save sent one request, to the address of the record. Shortened to its method, three headers and its body:
POST /maximo/oslc/api/os/mxapiwodetail/<id of the record>
x-method-override: PATCH
patchtype: MERGE
properties: wonum,description,wopriority,worktype,status,status_description,changeby,changedate
{"wopriority":3,"_action":"Change","href":"api/os/mxapiwodetail/<id of the record>","_bulkid":"1000"}Three things in this request are worth a second look.
The body has one attribute. We changed the priority, and the priority is all that travels, with three technical keys beside it. The description, the work type and the status stay out of the request.
The header properties is the schema. It asks Maximo to answer with these attributes after the save. The app then takes the answer into the record. That is how a value that Maximo sets during the save reaches the page without a second request.
The method is a POST that says PATCH. patchtype: MERGE tells Maximo to change the named attributes and to leave everything else as it is.
The answer came after about 150 milliseconds with status 200. itemsChanged was false again.
Step 3 · The hooks of a save#
The trace of the controller, from the change to the end of the save. On the page it starts with one more entry, which the application controller wrote when the app started:
ds.onValueChanged
page calls save()
ds.onBeforeSaveData
ds.onValueChanged
ds.onValueChanged
ds.onAfterSaveData
save() returnedonBeforeSaveData runs before the request, and onAfterSaveData after the answer. Between them, onValueChanged ran twice more. Those were the values of the answer: Maximo had set who changed the record and when.
So onValueChanged is no sign of a user at work. It also runs for values that arrive from the server. A hook that reacts to user input has to check which attribute changed.
A save with nothing to save is cheap. We called save() on the unchanged record: no request, no hook, and the call came back after 4 milliseconds.
Step 4 · Take a change back#
ds.undoAll();We changed the priority and typed into the description, and then called undoAll(). Both fields showed their old values again, itemsChanged was false, and no request went out. The datasource had kept the old values.
This is the call for a Cancel button. It needs no reload.
Step 5 · A save that Maximo refuses#
We set the work type to NOPE, which is no work type of our system, and saved.
| What we looked at | What we saw |
|---|---|
| the request | the same POST, with {"worktype":"NOPE", …} |
| the answer | HTTP 400, BMXAA4575E |
| the screen | a dialog “System message”: “Work Type NOPE is not a valid work type.” |
| the hooks | onBeforeSaveData, then onSaveDataFailed |
save() | it returned, and it threw no error |
itemsChanged | still true |
| the field | still NOPE |
Two points matter for your code.
The framework shows the message of Maximo on its own. Your code does not have to show it a second time.
save() does not throw when Maximo refuses. It returns an object that carries the error. Code that goes on after await ds.save() as if all were well will go to the next page with an unsaved record. Check the result:
const result = await ds.save();
if (result && result.error) {
return; // the record is unsaved, and the user has seen the message
}
// go on only from here
After a refused save the wrong value is still in the record. The user corrects it and saves again, or your Cancel button calls undoAll().
Step 6 · When somebody else changed the record#
The app loaded the work order. Then a second user changed the description and the priority in Maximo. In the app, we set the priority to 1 and saved.
The save went through with status 200, and nobody was warned. The request carried the priority alone, so Maximo changed the priority and left the new description of the other user alone. The answer brought that description into the app: after our save, the page showed the text of the other user and our priority.
So two users who change different attributes of one record both keep their change. Two users who change the same attribute get the value of the one who saved last. For most fields of a work order that is acceptable. For a field where it is not, such as a quantity that two people count, reload the record before the change and keep the time between load and save short.
The calls of this tutorial#
| Call | Requests | What it does |
|---|---|---|
| a changed value | 0 | sets itemsChanged, runs onValueChanged |
save() with a change | 1 | sends the changed attributes, takes the answer into the record |
save() without a change | 0 | returns at once |
undoAll() | 0 | takes back every unsaved change |
forceReload() | 1 | reads the record again |
What to read next#
Maximo-Datasource vs. JSON-Datasource shows what a save does on a datasource that reads a file of the app. Using Lifecycle Hooks Correctly covers the rules for hooks, which hold for the save hooks too.
IBM documents the elements and attributes of a datasource in the product itself. In the Application Configuration application, open the ? menu and choose Component Documentation. The headers of an update are described in IBM’s documentation of the Maximo REST API.
