Skip to Content
0
Jan 23, 2018 at 06:20 PM

SAPUI5 oModel.create not a function [sapui5 with odata service]

1323 Views

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