cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting records from Database using ODataModel Remove function

former_member243729
Participant
0 Kudos

Hi,

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
oDataMdl.remove("/<EntitySet>('Value_1')"

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

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor

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

Answers (2)

Answers (2)

maheshpalavalli
Active Contributor

You have to pass both keys as mentioned by jun.wu5..

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

https://stackoverflow.com/questions/46954621/how-to-create-entity-path-dynamically-in-ui5

Thanks

Mahesh

former_member243729
Participant
0 Kudos

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();

MessageBox.show("Success");

}.bind(this),

error: function(oError){
	MessageBox.show("Failed");
}					
}	
junwu
Active Contributor
0 Kudos

choose correct answer, and start a new question....