on 01-23-2018 6:20 PM
oModel.create is not a function
I am trying a basic CRUD operations example with sapui5 and odata.
Issue: Whenever i call oModel.create function it gives error: oModel.create... is not a function
onInit: function() {
var serviceURL = 'http://services.odata.org/V4/OData/OData.svc/Persons?$expand=PersonDetail';
var oModel = new sap.ui.model.json.JSONModel(serviceURL);
oModel.attachRequestCompleted(function(oEvent){
sap.ui.getCore().setModel(oModel);
});
}
/**************/
var oData = {
Name: '',
PersonDetail:{
Age: '',
Phone: '',
Address: {
Street: '',
City: '',
State: '',
ZipCode: '',
Country: ''
}
}};
oData.Name = sap.ui.getCore().byId('sNameInput').getValue();
oData.PersonDetail.Age = sap.ui.getCore().byId('sAgeInput').getValue();
oData.PersonDetail.Phone = sap.ui.getCore().byId('sPhoneInput').getValue();
oData.PersonDetail.Address.Street = sap.ui.getCore().byId('sStreetInput').getValue();
oData.PersonDetail.Address.City = sap.ui.getCore().byId('sCityInput').getValue();
oData.PersonDetail.Address.State = sap.ui.getCore().byId('sStateInput').getValue();
oData.PersonDetail.Address.ZipCode = sap.ui.getCore().byId('sZipCodeInput').getValue();
oData.PersonDetail.Address.Country = sap.ui.getCore().byId('sCountryInput').getValue();
console.log(oData);
var oController = sap.ui.getCore().byId('masterPage').getController();
var oController = sap.ui.getCore().byId('masterPage').getController();
var oModel = sap.ui.getCore().getModel();
oModel.create('/value',oData,null,{success: oController.fnSuccessHandler(), error: oController.fnErrorHandler()});
All the parameters passed to the create function are right still it is showing that create is not a function. Please help.. Thanks in advance
you need odatamodel to call "create"
you have a jsonmodel now, which will not do the job you intended.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@jun.wu5 is right, his answer should be marked as correct. Additionally, I suggest you to learn the basics of UI5 by reading the Walkthrough Tutorial. It covers some OData basics as well. Make sure you understand the difference between the ODataModel and the JSONModel!
Hi Swapnil Lahire the problem is that you're using the JSONModel. Those methods are only supported by ODataModel (you should use v2).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
change the model from json to odata model. add below line.
var oModel = new sap.ui.model.odata.ODataModel(serviceURL);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The sap.ui.model.odata.ODataModel has been deprecated long time ago. Instead use sap.ui.model.odata.v2.ODataModel, or if you can sap.ui.model.odata.v4.ODataModel. As you can see in the code abopve an V4 OData service is called, thus sap.ui.model.odata.v4.ODataModel should be used here.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.