Hi,
I'm trying to update my table using the oData Update. Below is the code
press: function(){ // BUTTON PRESS var currentContext = this.getBindingContext(); var oCurrentModel = currentContext.getModel(); selectedProductID = oCurrentModel.getProperty("ID", currentContext); if(this.getText()==='Edit'){ //oTable.setEditable(true); this.setText('Save'); oCurrentModel.setProperty('editable',true,currentContext); } else{ //UPDATE OCCURS HERE this.setText('Edit'); oCurrentModel.setProperty('editable',false,currentContext); var oParams = {}; oParams.fnSuccess = function(){ alert("Update successful");}; oParams.fnError = function(){alert("Update failed");}; oParams.bMerge = true; oUpdate = oCurrentModel.getData(); oModel.update('/CarbonData('+selectedProductID+')', oUpdate, oParams); } }
Below is the screenshot I get in FireBug
The code works if I assign values to individual variables. For Ex:
function updateDetails() { var oProduct = oModel.getData('/CarbonData('+selectedProductID+')'); oProduct.ID = sap.ui.getCore().byId("Id_m").getValue(), oProduct.Loc_ID = sap.ui.getCore().byId("loc_id_m").getValue(), oProduct.Label = sap.ui.getCore().byId("Label_m").getValue(), oProduct.Region = sap.ui.getCore().byId("Region_m").getValue(); oProduct.Country = sap.ui.getCore().byId("Country_m").getValue(); oProduct.City = sap.ui.getCore().byId("City_m").getValue(); oProduct.Emitter = sap.ui.getCore().byId("Emitter_m").getValue(); oProduct.Quarter = sap.ui.getCore().byId("Quarter_m").getValue(); oProduct.Carbon_Footprint = sap.ui.getCore().byId("Carbon_Footprint_m").getValue(); oModel.update('/CarbonData('+selectedProductID+')', oProduct, null, function(data) { sap.ui.commons.MessageBox.show("Product " + oProduct.ID + " Updated!", sap.ui.commons.MessageBox.Icon.SUCCESS, "Product Saved", sap.ui.commons.MessageBox.Action.OK); }, function(err) { //Error Callback: alert("Error occurred " + err.message); }) };
But I can't keep it this way as I need to make it more dynamic.
Can anyone help me out?