cancel
Showing results for 
Search instead for 
Did you mean: 

How to attach FE OP Controller Extension function to OData V4 dataReceived event?

AlwinvandePutTM
Explorer
0 Kudos
164

I want to catch the dataReceived event of OData V4 model which is used by a Fiori Elements Standard Object Page in a Controller Extension. So that after every time the data is loaded or refreshed on the screen, I get into my custom Controller Extension function.

At onAfterRendering the data is not yet available.
So I have to attach an event to the model.

When I tried this

 

onAfterRendering: function () {
  var oModel = this.base.getExtensionAPI().getModel();
  oModel.attachEvent('dataReceived', myFunction);
},

 

I saw that only events messageChange and sessionTimeout are available in the model.

So maybe they are available after the ExtensionAPIPromise, but it the function is not called.

 

onInit: function () {
  var oView = this.getView();
  ExtensionAPI.getExtensionAPIPromise(oView).then(
    function (oExtensionAPI) {
      oExtensionAPI.attachPageDataLoaded(function (event) {
        var sPath = event.context.sPath;  // get the path
        var oData = event.context.getModel().getProperty(sPath); 
      }.bind(this));
    }.bind(this)
  )
},

 

I also tried this. but the event is not triggered. Probably because it creates a new binding.

onAfterRendering: function () {
  var oModel = this.base.getExtensionAPI().getModel();
  var oContextBinding = oModel.bindContext("/Run");
  oContextBinding.attachEvent('dataReceived', function (event) { 
    console.log('Testing...')
  })
},

Could you help me?


 

View Entire Topic
junwu
SAP Champion
SAP Champion
0 Kudos

this should work, but where is your myFunction. can you also try model.attachDataReceived

onAfterRendering: function () {
  var oModel = this.base.getExtensionAPI().getModel();
  oModel.attachEvent('dataReceived', myFunction);
},

 

 

AlwinvandePutTM
Explorer
0 Kudos

I tried your solution. To be sure I created a new project.

onAfterRendering: function () {
  console.log('onAfterRendering');

  var oModel = this.base.getExtensionAPI().getModel();
  oModel.attachEvent(
    'dataReceived',
    function(oEvent) {
      console.log('dataReceived');
    }
  );
}

 It results in 

ODataModel-dbg.js:509  Uncaught (in promise) Error: Unsupported event 'dataReceived': v4.ODataModel#attachEvent
    at w.attachEvent (ODataModel-dbg.js:509:10)
    at f.onAfterRendering (RunObjectPageControllerExtension.controller.js:21:12)
    at o.<computed> [as onAfterRendering] (ControllerExtension-dbg.js:174:21)
    at b.fireEvent (EventProvider-dbg.js:247:11)
    at d.fireEvent (Element-dbg.js:626:23)
    at f.fireAfterRendering (ManagedObjectMetadata-dbg.js:789:44)
    at g.onAfterRendering (View-dbg.js:752:3)
    at d._handleEvent (Element-dbg.js:342:21)
    at h1 (RenderManager-dbg.js:1285:15)
    at i1 (RenderManager-dbg.js:1370:4)

 When I debug attachEvent, only events messageChange and sessionTimeout are supported. UI5 version is 1.102.2.

AlwinvandePutTM
Explorer
0 Kudos
Is see now that dataReceived is Since: 1.106.0. I work on 1.102.2.