cancel
Showing results for 
Search instead for 
Did you mean: 

Uncaught TypeError: Cannot read properties of undefined (reading 'getView')

Former Member
0 Kudos
2,722

Hello All,

I have created a custom UI5 application.

But while reading the data through the following query, I am getting an error- “Uncaught TypeError: Cannot read properties of undefined (reading 'getView') at success”

this.oModel.read("/ET_Deal_CustListSet", {

success: function (odata) {

var CustJsonData = new JSONModel(odata.results);

this.getView().setModel(CustJsonData, "ET_CustList");

}

});

I can view the data in Network tab - $metadata(status: 200), $batch(status: 202). But this odata query results in an error.

Please advise.

Regards- Meenakshi

Accepted Solutions (1)

Accepted Solutions (1)

radoslaw_kiela2
Participant

Hi,

You need to bind "this" to the success callback fn:

this.oModel.read("/ET_Deal_CustListSet", {
success: function (odata) {
var CustJsonData = new JSONModel(odata.results);
this.getView().setModel(CustJsonData, "ET_CustList");
}.bind(this) });

or save the outer context and use it in the scope of the success callback fn:

var that = this;
this.oModel.read("/ET_Deal_CustListSet", {
success: function (odata) {
var CustJsonData = new JSONModel(odata.results);
that.getView().setModel(CustJsonData, "ET_CustList");
} });

Br,

Radoslaw

Former Member
0 Kudos

Thank you so much. It worked.

Answers (1)

Answers (1)

maciejp
Explorer

Hi meenakshi.raina, inside a function, "this" is not referencing to the controller as you assume. The easiest way to fix this is to use the arrow function. This will look like this:

this.oModel.read("/ET_Deal_CustListSet", {
success: (odata) => {
var CustJsonData = new JSONModel(odata.results);
this.getView().setModel(CustJsonData, "ET_CustList");
}
});