cancel
Showing results for 
Search instead for 
Did you mean: 

Update binding after CRUDQ operation

former_member602416
Participant
0 Kudos

Hi,

I need to update binding after CRUDQ operation on oData service. In my code i have deleted one of the card details which gives success message but page does not display the updated binding unless page refreshed manually. Can someone please advice so page does not display the deleted card as soon as it got deleted.

I have called refresh() in the code like below but it still does not show the updated binding.

  else if (this.mode == 'DeleteCard'){

  var oModel3 = sap.ui.getCore().byId("CardRBG").getModel("CardModel");

  // Index of selected radio item

  var oIndex = sap.ui.getCore().getControl("CardRBG").getSelectedIndex();

            if(oIndex == -1){sap.ui.commons.MessageBox.alert("Please select a card to delete")};

  // Read result

  var oResults = oModel3.getProperty("/");

  var oUCRN =  oResults[oIndex].UCRN;

  var oBusPartner =  oResults[oIndex].BusPartner;

  var oCardKey = oResults[oIndex].Card_Key;

  var oCardMask = oResults[oIndex].Card_Mask_num;

  var requrl = "/sap/opu/odata/SAP/Service/PaymentCardSet(UCRN='"+oUCRN+"',Card_Key='" + encodeURIComponent(oCardKey) + "',Card_Mask_num='"+ encodeURIComponent(oCardMask).replace(/\*/g,"%2A") + "')";

  OData.request({requestUri: requrl , method: "GET", headers:{"X-Requested-With": "XMLHttpRequest",

  "Content-Type": "application/json",

  "DataServiceVersion": "2.0",

  "MaxDataServiceVersion": "2.0",

  // "Accept": "application/json",

  "X-CSRF-Token":"Fetch"}},function(data, response){

  var header_xcsrf_token = response.headers['x-csrf-token'];

  console.log(header_xcsrf_token);

  var url = "/sap/opu/odata/SAP/service/PaymentCardSet(UCRN='"+oUCRN+"',Card_Key='" + encodeURIComponent(oCardKey) + "',Card_Mask_num='"+ encodeURIComponent(oCardMask).replace(/\*/g,"%2A") + "')";

  var method = "DELETE";

  requestObj.requestUri = url;

  requestObj.method = method;

  requestObj.headers = {

  "X-Requested-With": "XMLHttpRequest",

  "Content-Type": "application/json",

  "DataServiceVersion": "2.0",

  "MaxDataServiceVersion": "2.0",

  //"Accept": "application/json",

  "X-CSRF-Token": header_xcsrf_token};

  OData.request(requestObj, function(data, request){

  sap.ui.getCore().byId("CardRBG").getModel("CardModel").refresh();

  sap.ui.getCore().byId("CardRBG").getModel("CardModel").updateBindings();

  sap.ui.commons.MessageBox.show("Card Sucessfully Deleted", null, "Success", 'OK' );

  //alert("Card Sucessfully Deleted");

  },function(err){

  sap.ui.commons.MessageBox.alert("Failed to delete selected card");

  }

View Entire Topic
santhu_gowdaz
Active Contributor
0 Kudos

after deleted successfully again u need to do table binding.(call backend to get update data)

former_member602416
Participant
0 Kudos

Already written below to update binding after calling the deleted . Anything else needs to do?

  sap.ui.getCore().byId("CardRBG").getModel("CardModel").updateBindings();

kedarT
Active Contributor
0 Kudos

Hi,

Use refresh() on the model.

santhu_gowdaz
Active Contributor
0 Kudos

Actually what i'm telling is copy paste whole get table data code inside the success method. may it work.

former_member602416
Participant
0 Kudos

Not Helpful

santhu_gowdaz
Active Contributor
0 Kudos

use this code,

// Request for fatching Token
   OData.request 
   ({  
   requestUri:thaturl.url,  
   method: "GET", 
   headers:  
   {  
   "X-Requested-With": "XMLHttpRequest",
   "Content-Type": "application/atom+xml",
   "DataServiceVersion": "2.0", 
   "X-CSRF-Token":"Fetch"   
  
   },  
   // Request For Postong data to SAP System
   function (data, response) 
  
   // collecting data from view
   header_xcsrf_token = response.headers['x-csrf-token'];
   // Request To backend
   OData.request 
   ({  
   requestUri: thaturl.url+"/DeliveryHdrs",  
   method: "DELETE",
   headers: {                    

   "X-Requested-With": "XMLHttpRequest",                  
   "Content-Type": "application/atom+xml",
   "DataServiceVersion": "2.0", 
   "Accept": "application/atom+xml",  
   "X-CSRF-Token": header_xcsrf_token   

   }, 
   },
   // Response after posting and set message
   function (data, response) 
   {  
   //Deleted Successfully msg
   //Table Refresh Code.
   },  
   // Error Handling
   function (err)  
  
   //display Deleted unsuccessfully error
  
   ); 
   },  

   // error Handling when request or responce not working
   function (err)  
   {
   //display HTTP Requset Responce ErrorMsg;
  
   );
former_member602416
Participant
0 Kudos

Below has resolved the issue -

document.location.reload(true);