Skip to Content

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

Jan 23 at 06:20 PM


avatar image

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 = '$expand=PersonDetail'; 
  var oModel = new sap.ui.model.json.JSONModel(serviceURL);

var oData = {
		Name: '',
			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();
		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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Jun Wu Jan 23 at 06:53 PM

you need odatamodel to call "create"

you have a jsonmodel now, which will not do the job you intended.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

@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!


Thank you Jun Wu what if i had to use JSONModel and create entry in the service ?

Swapnil Lahire

had to?

who is forcing you???

Irfan Gokak Jan 24 at 07:10 AM


change the model from json to odata model. add below line.

var oModel = new sap.ui.model.odata.ODataModel(serviceURL);
Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.

Emanuele Ricci Jan 25 at 09:35 AM

Hi Swapnil Lahire the problem is that you're using the JSONModel. Those methods are only supported by ODataModel (you should use v2).

10 |10000 characters needed characters left characters exceeded