onBeforeSaveData, and your check goes there. It passes your test. Then a work order changes its status in the app, and your check never ran. This page shows why, with four measurements on one work order.MAS 9.2 series wrong beliefs
This is the first single belief from Ten Things Every Maximo Developer Believes That Are Wrong. We measured it on our test system, on the MAS 9.2 series, in the browser preview of our Components Explorer.
The belief#
“onBeforeSaveData runs before every write of the datasource. A status change is a write. So this hook is the place to intercept a status change.”
The belief comes from the name, and from the Maximo server. On the server, a developer puts a rule on the object and expects it on every path that saves the object. The same developer expects one door on the client too.
What we measured#
Our page has one datasource on one work order. Its controller listens in four ways, and every listener writes a line into a trace:
class FsActionDsController {
onDatasourceInitialized(ds) {
// a subscription to the event under its own name
ds.on('before-invoke-action', () => ctlTrace("ds.on('before-invoke-action')"));
}
// the save hook
onBeforeSaveData() {
ctlTrace('ds.onBeforeSaveData');
}
// the name a developer would guess for an action
onBeforeInvokeAction() {
ctlTrace('ds.onBeforeInvokeAction');
}
// a method whose name is the name of the event
'before-invoke-action'() {
ctlTrace("ds['before-invoke-action']");
}
}The block is a shortened form of the controller of our page. The real one builds these methods from two lists of names, and it has the same kinds for the events after a write and for a failure.
Then we wrote to the work order in four ways:
| What the page did | onBeforeSaveData | onBeforeInvokeAction | method 'before-invoke-action' | ds.on(…) |
|---|---|---|---|---|
changed the priority, then save() | ran | silent | silent | silent |
set status as a value, then save() | ran | silent | silent | silent |
invokeAction('changeStatus') | silent | silent | ran | ran |
| the same action with a status that does not exist | silent | silent | ran | ran |
The third row is the belief, broken. The status of the work order changed from WAPPR to APPR, Maximo wrote a row into the status history, and the save hook heard nothing.
The middle column is the second surprise. The method with the guessed name, onBeforeInvokeAction, never ran either. The action has events, and they arrive under their own names, with the hyphens.
![Three screens of the lab page. First, the trace after a save: ds.onValueChanged, page calls save(), ds.onBeforeSaveData, ds.onValueChanged, ds.onAfterSaveData, save() returned. Second, the trace after the action: page calls invokeAction(changeStatus), ds.on(‘before-invoke-action’), ds[‘before-invoke-action’], ds.on(‘after-invoke-action’), ds[‘after-invoke-action’], invokeAction() is over. Third, a system message: the synonym value NOPE is not valid for the domain WOSTATUS, with the code BMXAA4024E.](/mobile/guides/controllers/wrong-belief-onbeforesavedata-intercepts-a-status-change/status-change-three-traces-phone_hu_c37f8ffbc8cd0b1f.webp)
Two requests, two families#
The network tab shows why the two are different things. A save sends the changed attributes to the record:
POST …/os/mxapiwodetail/{id}
x-method-override: PATCH
{"wopriority": 2, …}The action calls a method of the object in Maximo and names it in the address:
POST …/os/mxapiwodetail/{id}?action=wsmethod:changeStatus
{"status": "APPR"}The framework has one family of events for each. A controller gets the save family as onBeforeSaveData, onAfterSaveData and onSaveDataFailed. The action family is before-invoke-action, after-invoke-action and invoke-action-failed. On our system these three reached a controller only under these names.
The action that fails#
We asked for a status that does not exist. Maximo answered with HTTP 400, and the framework showed its own system message with the text of Maximo and the code BMXAA4024E. The event invoke-action-failed ran. Our call of invokeAction returned normally, and the code after it went on. The status of the work order stayed as it was.
So a line after await ds.invokeAction(…) is no proof that the action worked. Listen for the failure event, or read the record again.
A listener hears, and the action goes on#
Can a listener stop the action? We tried it in the console of the browser. We added one more listener for before-invoke-action to the datasource, and its only line throws an error. Then we changed the status with the button of the page.
The listener ran once. The request went out all the same, Maximo answered with 200, and the status changed. On our system a listener that throws could watch the action, and it did not hold the action back.
The event does tell a listener what is going on. It carried three things: the datasource, the name of the action, changeStatus, and the options of the call with the new status in them.
The status as a value#
The second row of the table deserves a word. We set status on the record as a plain value and called save(). On our system Maximo accepted it: the status changed, and the status history got its row. This path does run onBeforeSaveData.
A status can therefore change through two doors, and a check in one hook guards one of them. IBM’s Technician app changes the status of a work order with the action, in several places of its source. We found no onBeforeSaveData in that app.
Check it yourself#
- Open the datasource controller of a page that changes a status.
- Add a line that logs to the console in
onBeforeSaveData, and one in a method named'before-invoke-action'. - Change a status in the app, with the console open.
- Read which of the two lines appears.
The model that holds#
- Saves and actions are two families. A save changes attributes. An action calls a method of the object: a status change, a workflow step, an approval.
- A listener is for watching. A method named
'before-invoke-action', ords.on(), hears the action with its name and its options. It is a place to log, to count or to update the page. - A check that must stop the change sits before the call. In our measurement a listener that throws did not stop the action. Our recommendation is to put such a check into the method that makes the call, before the call.
- The rule itself belongs on the server. A client has more than one door, and another app has its own doors. A rule that must always hold is an automation script or a condition in Maximo.
What to read next#
Saving and Updating Data measures the save family in full. Using Lifecycle Hooks Correctly lists the hooks of pages and datasources, and Event Handling Patterns shows what a handler receives.
IBM describes actions of an object structure, with the action=wsmethod: parameter, in its documentation of the Maximo REST API.
