Skip to Content

Deleting records from Database using ODataModel Remove function


My back-end table has 2 primary keys and it expects me to pass both the values to remove/delete records from the database.

ODataModel.remove() method doesn't have any PayLoad or filters parameters. The URL parameter which is available I guess cannot be used to pass values, it is for $expand, $top, etc. So what's the way out here....

//Neither this works
oDataMdl.remove("/<EntitySet>?$filter=Key1 eq 'Value_1'"
//Nor this works

On top of this I need to pass two values and just one. Any suggestion please ?

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Oct 11, 2019 at 11:46 PM

    oDataMdl.remove("/<EntitySet>(keycolumn='Value_1', keycolumn2='key2')"

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 12, 2019 at 07:27 AM

    You have to pass both keys as mentioned by Jun Wu..

    You can get the path in a dynamic way by using create key. See the question below.



    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 14, 2019 at 08:39 PM

    I tried Jun Wu's suggestion last week and it worked. Thanks Mahesh for showing me an alternate option as well.

    Now then,..once I delete a record, I am trying to refresh my model so the table to which the model is bound shows latest set of records...which is not working though. May I know how we can refresh the model after delete method is invoked. Or, the only way to show latest records (post deletion) in the table is to again call a READ method and get the records from the back-end ?

    var oTab = sap.ui.core.Fragment.byId("DOCSUPLOAD", "idTabDocList").getModel("docsList");
    var oDataMdl = this.getOwnerComponent().getModel();
    oDataMdl.remove("/<EntitySet>(keycolumn='Value_1', keycolumn2='key2')", 
    success: function(oData, oResponse){
    sap.ui.core.Fragment.byId("DOCSUPLOAD", "idTabDocList").getModel("docsList").refresh();"Success");
    error: function(oError){"Failed");
    Add a comment
    10|10000 characters needed characters exceeded

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.