cancel
Showing results for 
Search instead for 
Did you mean: 

In View Controller: OData is not defined

Former Member
0 Kudos

Hi Experts,

I am new in SAP UI5, I referred the example about OData & UI5 for CRUD operations.

When I code the update function in the view controller, it showed error "OData" is not defined. However I searched on the internet, there are many cases about CRUD operation used OData.request, I don't know why there is error in my case.

BTW, I used the SAP Web IDE local version.

As below is my coding with error in SAP Web IDE. As attached is my source code of view controller.

Thank you in advance and looking forward to your reply.

Accepted Solutions (1)

Accepted Solutions (1)

maheshgonda
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

either define odata model

sap.ui.define([

  "sap/ui/core/mvc/Controller",

"sap/ui/model/odata/ODataModel "

], function(Controller,OData)

or before u do service call get instance

var OData = new sap.ui.mode.odata.ODataModel();

OData.request(........)

Former Member
0 Kudos

Hi Mahesh,

Thank you so much for your prompt feedback. The definition issue is already fixed.

However a new problem occurred. When I run UI5 application in Chrome Debug, it showed error message "OData.request is not a function". Do you have any idea about this issue?

Thanks in advance.

maheshgonda
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi ,

sorry i have not seen in API

if you are using

var OData = new sap.ui.mode.odata.ODataModel();

then there is no method called "request"

OData.request(........)  // will give error

so u have to use only  update/read/create i.e

OData.read(....)  

OData.update(....) 

OData.create (....) 

for API reference : JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel

i think in older version of odata may have request(i.e OData.request ) method (i am not sure about this)

Former Member
0 Kudos

Hi Mahesh,

Thank you so much for your explanation.

The issue is solved by using the solution you mentioned.

I also found SAP help about this topic.

OData Write Support - UI Development Toolkit for HTML5 (SAPUI5) - SAP Library

Really appreciate your kindly support.

Thanks and wish you have a good day.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Scott,

I don't know why are you using the oData.request() ..even if there is no variable name oData.

To simply call the Get service .. why can't you use read() method of oData Model ...

var oModel = new sap.ui.model.odata.ODataModel(url,true);

oModel.read();

reference : JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel

thanks

Viplove

Former Member
0 Kudos

Hi Viplove,

Thank you so much for your feedback.

To be honest, I even don't know why OData.request() is needed.

What I want to do is to implement update function by using UI5 and OData. So I refer to the below example. However for some UI5 code, I don't quite understand it.

Since I am just new in SAP UI5, I believe I must have asked so many silly questions, sorry about that.

Anyway, thank for your suggestion. I will check it later.

Cheers.

suresu22
Explorer
0 Kudos

Hi ,

Just download data.js file from datajs - JavaScript Library for data-centric web applications - Home and include it in index.html.

or

jQuery.sap.require("sap.ui.thirdparty.datajs"); in sap.ui.getCore().attachInit

U got error oData is not defined because u didn't included datajs library

Thanks

Suresh

former_member182862
Active Contributor
0 Kudos

HI Scott

You are referring to a old exercise.

here is the oData API

JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel

Former Member
0 Kudos

Hi Suresh,

Thank you so much for your comments.

I already solved the issue. The reason is OData.request() is the old way to operate OData for CRUD. The new way is mentioned at below link.

OData Write Support - UI Development Toolkit for HTML5 (SAPUI5) - SAP Library

Anyway, I really appreciate your help.

Cheers.

Former Member
0 Kudos

Hi Dennis,

Thank you so much for your help.

The problem already solved.


Cheers.

former_member203031
Contributor
0 Kudos

Hi Scott,

You need define the odata model to use the respective functionality like

var oModel = new sap.ui.model.odata.ODataModel(url,true);

then only you can use

oData.request();

Hope this will works.

Thanks,

Deepak.    

Former Member
0 Kudos

Hi Deepak,

Thank you so much for your help.

I tried your solution, unfortunately it cannot work. The issue remains.

Anyway, I really appreciate your input.

Thanks.