Skip to main contentMAF Configuration Practices

Reuse page datasource controller from another page

About this task

This is an sample to show how to use an existing datasource’s controller from a page and reuse in another page. In thise case there is a existing WorkOrderCreateController to be reused on a new Quick Reporting Page for Techmobile. It is tempting to think on moving out the dsCreateWO datasource of the page and up to the application. The problem with moving the datasource and re-using the WorkOrderCreateController is that the controller code has references to dsCreateWO that require it to be in the page. Instead, the developers should have used this.app.findDatasource(‘dsCreateWo’); to find the datasource. To get around this problem without requiring a change to the Techmobile application, the AppCustomizations.js can trap the pageInitialized call for the new Quick Reporting page, and set the existing datasource as part of the new page.

Procedure

Step 1: In pageInitialized event, check for the right page, ensure the datasource does not exist in the page, fetch its reference using this.app.findDatasource and set it to the new page.

pageInitialized(page) {
if (page.name === 'quickReporting') {
if (page.datsources['dsCreateWO'] === undefined) {
page.datasource['dsCreateWO'] = this.app.findDatasource('dsCreateWO');
}
}
}