Skip to Content

Extending a Fiori Elements Object Page to fire a function on every page switch

Hi experts,

I have a CDS view exposed as a Fiori Elements application. I would like to add a custom table to the Object Page screen you navigate to when you click on the line from the List Report. I have successfully done this by creating an Extension, and now I have a view.xml and a controller.js which adds the Facet to the Object Page, and the table is set up in the XML view. These files are in the 'ext' folder in the app folder in WebIDE Full Stack.

My question is how can I add some functionality to the controller to detect every page switch? I want to update the JSONModel with the data for the current line item I'm looking at, in order to populate the custom table.

I have looked at the attachRouteMatched() function of the Router, but this does not fire the first time, and seems to fire on navigation back to the List Report too, which means the Model is updated with the previous item's data, not the current one.

I have tried adding an event delegate of onBeforeShow which is what I use on my normal SAPUI5 apps, but this does not work here. Using onBeforeRendering lifecycle of course only runs the first time the Object Page is navigated to.

Does anyone know how I can fire a function every time the app navigates to the Object Page from the List Report?

Many thanks

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • May 16 at 09:38 PM

    Hi Matthew Kennedy,

    You need to create the extension for the object page(webide) then in the controller you need to write the below code.

    sap.ui.controller(listreptest.ext.controller.ObjectPageExt", {
    	onInit: function (oEvent) {
    
                    // The below function will get called for every binding change
    		this.extensionAPI.attachPageDataLoaded(function (oEvent) {
    			
    		}.bind(this));
    	}
    });

    Thanks,

    Mahesh

    Add comment
    10|10000 characters needed characters exceeded