0

I am new to SAPUI5 and want to update an entity data using oListData. I am not able to find any tutorial that explicitly explains this. My onSave function looks like this:

               onSave: function() {
               var oDialogContext;
                 var oNewItem = {
          
                };
                var oForm = this.byId("companyObjectEditForm");
                var description = this.getView().byId("description").getValue();
                var validation = this.getView().byId("invalidCombo").getValue();
                oNewItem.Beschreibung = description;
                const compareValue1 = validation.localeCompare("Ungueltig")
                 if(validation === "Ungültig"){
                    oNewItem.Ungueltig = 1;
                 }
                 else{
                   oNewItem.Ungueltig = 0;
                }
                var oView = this.getView();
                function resetBusy() {
                 oView.setBusy(false);
                }
                oView.setBusy(true);
               // oListBinding.create(oNewItem);          
            this.getView().getModel().submitBatch("cmpchange").then(resetBusy, resetBusy);
            this.onNavBack();

        },

I am setting the binding using the following code:

         var path = this.getAppModel().getProperty("/selectionPath");
                    //oListBinding = this.getView().getModel().bindList({path,parameters: { 
           "$$updateGroupId": 'cmpchange' }});

My path is like this Company(id) -> which depicts the record to be updated. The oListBinding.create(oNewItem) works completely fine and creates a new entity however there is no function explicitly mentioned for updating.I have mostly seen updates done relevant to binding. Can anyone review the code and point out if the binding is correct or not.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Maliha
  • 45
  • 1
  • 5

1 Answers1

0

If you want to update a specific entry for which you already know the path you can do it like this:

const oV4Model= this.getView().getModel();
const oContext = oV4Model.bindContext("Company('1234')", null, {
     $$updateGroupId: "cmpchange"
});

oContext.setProperty("property", "value");
oContext.setProperty("otherProperty", "value");

// this will send a post request with both changed properties
oV4Model.submitBatch("cmpchange").then(resetBusy, resetBusy);

or you could use the newly created context instead:

const oContext = oListBinding.create(oNewItem);

or if you don't know the paths you could request the contexts through the list binding:

// requestContexts will request the entities in a given range, if not specified defaults to [0, the set model size limit].
oListBinding.requestContexts().then(aContexts => {
    for (const oContext of aContexts) {
       // ...
    }
});
Flo
  • 29
  • 5