Skip to Content

sapui5 -CRUD operations

Hi All,

OI am learning CRUD operations in sapui5. i have created a simple app. now trying to EDIT the details in the app. I have attached the error and the code edit.png. Please suggest me how to resolve it 

	     			var sLocalPath,
	     		sUrl = "", 
	     	//	oRouter = this.getRouter(),
	     		sPath = this.getView().getElementBinding().getPath(), 
	     	//	oModel = this.getModel(),
	     	    oModel = this.getView().getModel(),
	     		oObject = oModel.getProperty(sPath), 
	     	//	oBundle=this.getResourceBundle();
	     		oBundle = this.getOwnerComponent().getModel("i18n").getResourceBundle();
         		sUrl = sUrl + "/Vendors/" + oObject.ID; 
	     		sLocalPath = sPath; 
	     		oModel.attachEventOnce("requestCompleted", function(){
	     			this.getModel("viewModel").setProperty("/createMode", false);
	     		}, this);
	     	oModel.attachEventOnce("requestFailed", function(){"updatedFailed"));
	     	oModel.saveEntry(oObject, sUrl, sLocalPath);

I am getting error as oModel.saveEntry is not a function. The method is implemented in another JS file

edit.png (50.7 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Aug 06, 2020 at 03:30 AM

    Hi Dipti,

    For doing CRUD operations, you can follow the documentation maintained in SDK.

    Regarding the particular error that you are getting, this is because your statement oModel.saveEntry(param1, param2, param3); is understood by the compiler as a method being invoked for oDataModel library (sap.ui.model.odata.v2.ODataModel - if you are using v2 model). Since no such method exists in the library, you get the attached error.

    Since this method has been defined by you in a separate js file, what you essentially need to do is extend that js file in your controller. This will allow you to access the saveEntry function.

    Do let me know in case you are still facing an issue.

    Best Regards,


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 06, 2020 at 12:58 PM
    	], function(JSONModel){
    		"use strict";
    		return JSONModel.extend("sapui5.test.mvcapp.model.AppModel", {
    			saveEntry: function(oObject,sUrl, sLocalPath){
    					var that = this, 	oData;
    				oData = JSON.stringify(oObject);
    					type: "PUT", 
    					contentType: "application/json", 
    					data: oData, 
    					dataType: "json", 
    					success: function(){
    						that._updateModel(sLocalPath, oObject); 
    					error: function(){
    			_updateModel: function(sLocalPath, data){
    			this.setProperty(sLocalPath, data);
    			}		});	});
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 06, 2020 at 01:07 PM

    Hi Dipti,

    As stated before, whenever you invoke a method by first appending the standard UI5 control library, the method is searched in that particular class. So invoking as

    oModel.saveEntry(oObject, sUrl, sLocalPath);

    is essentially making the renderrer search for saveEntry method in the oDataModel.v2 class. This is the reason you are getting the error in console log.

    Instead you should invoke the method as:

    saveEntry(oObject, sUrl, sLocalPath);

    When you invoke the method as above, the renderrer will lookup this method in the current controller instance. Since the AppModel js is also included in the sap.ui.define, the method will be recognized and executed.

    Do let me know in case you still face an issue.

    Best Regards,


    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Rohit,

      I am able to resolve the error. By adding the below piece of code in Edit Controller.

      var oAppModel = new AppModel();

      oAppModel.saveEntry(oObject, sUrl, sLocalPath);

      Now I am able to enter the the method that was defined in another JS file. But the new issue is in that particular session all my changes are coming but when ever I am reloading the App all the changes are going away it is showing the originalvalues. I am thinking that this changes are going upto "Model" level but only upto data file. so when i am rerunning original data is coming from file.

      Please let me know.


Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.