MAS 9.2 series framework 3.2.8xx lookup goes through the app
This page is about where objects live. For where values live, which is a separate question with its own three answers, see Understanding State Management.
The patterns come from the apps that IBM ships with a 9.2-series install. The demonstration runs in our Components Explorer, a small Maximo Mobile app we built for these articles, in the preview of our MAF editor. Details move with each release, and the shape holds.
The containment tree#
An app is a tree, and the shape of that tree is short enough to hold in your head.
- The application is the root, and it holds pages along with datasources and dialogs of its own.
- A page holds its own datasources and dialogs, and it can hold child pages.
- A datasource can hold other datasources, which is how a child list follows the record its parent is showing.
- A dialog is a container in its own right, and it can hold datasources of its own.
Declaring something inside a page is what makes it that page’s business, while the same element declared at application level belongs to the whole app and every page can see it.
Where things are actually declared#
Sorting the datasource and dialog elements of the shipped apps by the element that encloses them gives the picture.
| Declared inside | Datasources | Dialogs |
|---|---|---|
| A page | the most common place | by far the most common place |
| The application | common | occasional |
| Another datasource | common | never |
| A dialog | very rare | never |
Both lean page-scoped, and dialogs lean much harder. Datasources sit inside a page more often than at application level, while dialogs sit inside a page far more often than anywhere else. A dialog usually belongs to the screen that opens it, and a datasource is more often shared.
The nested datasources are the quiet case, and they are the most useful one. A datasource declared inside another follows its parent’s current record, which is how a work order’s tasks or a record’s attachments stay in step without any code at all.
How lookup actually works#
Every scope object can find a datasource by id, and the search they run is different.
this.app.findDatasource("woDS"); // searches every page in the app
this.page.findDatasource("woDS"); // searches this page
The application’s version walks the whole tree while the page’s version stays local. Both take the same argument and both return the datasource or nothing, which is why the choice is easy to make without thinking about it.
IBM’s developers almost never think about it. Calls through the application object far outnumber calls through a page, so the wide search wins by a large margin.
The gap between those two numbers#
Put the two observations together and the tension is clear: datasources are declared narrowly, mostly inside one page, and then looked up widely, through the one object that searches everything.
That combination works perfectly well, and it carries three consequences worth knowing about.
Ids have to be unique across the app in practice. The framework scopes them by container, and a search that walks every page will return the first match it finds. Two pages with a datasource called listDS is legal and it is a trap.
A lookup can succeed from anywhere, once the other page has been opened. Reaching a datasource that belongs to a different page is one line, and nothing warns you. That is convenient when two screens genuinely share data, and it quietly couples them when they do not. It also depends on the path the user took, as the test below shows.
The local search is the honest one. When a controller only ever touches its own page’s data, this.page.findDatasource says so, fails fast when the datasource is somewhere else, and documents the boundary for the next reader.
Reaching the other kinds of object#
| To find | Call |
|---|---|
| A datasource | findDatasource(id) |
| A dialog | findDialog(id) |
| A page | findPage(name) |
Dialogs have a second, more common route. showDialog(id) opens one by id from the page that owns it, and it is used more often than findDialog. Most code wants a dialog on screen, and very little of it wants to inspect one.
A button opens a dialog of its own page by id, with no code at all:

<button id="fs_c_scope_open" kind="secondary" label="Open the dialog of this page"
dialog="fs_c_scope_dlg"/>
<dialogs id="fs_c_scope_dialogs">
<dialog id="fs_c_scope_dlg" title="A dialog of this page"
primary-action-text="Close" on-primary-action="closeDialogs"/>
</dialogs>A test of the two lookups#
Our test page looks up two datasources. fs_c_scope_ds is declared on the page itself. fs_l_panels_ds is declared on another page of the same app.
lookupBoth(id) {
const found = (ds) => (ds ? 'found' : 'not found');
this.page.state.pageOwn = found(this.page.findDatasource('fs_c_scope_ds'));
this.page.state.pageOther = found(this.page.findDatasource(id));
this.page.state.appOther = found(this.app.findDatasource(id));
}The page finds its own datasource and never the other one. The application found the other one only after that page had been opened in the session. In a fresh session, app.findDatasource answered “not found” as well:

So a lookup through the application works for data the user has already reached. Code that must run before that page was ever shown should not count on it.
Four rules that follow#
- Declare a datasource in the narrowest scope that works. Put it in the page unless a second page genuinely needs it, then move it up and accept that it now lives for the whole session.
- Give every datasource an id you would be happy to grep for.
woListDSsurvives a wide search.listDSdoes not. - Use the page lookup when the data is the page’s own. It is the same length to type and it fails in a way that tells you something.
- Nest a child datasource instead of wiring one by hand. If a list has to follow the record above it, declaring it inside the parent is what the nested cases in the corpus already do.
What to read next#
- Datasources, the Heart of the App for what you have found once you find it.
- Understanding State Management for the same question asked about values.
- Controller Basics for where these lookups get written.
