SAPUI5 Development

how to do OData update operation from SAPUI5 Application?

                  The update operation comes into play whenever an existing entry resource needs to be changed.The update function triggers a PUT/MERGE request to an OData service which was specified at creation of the OData model.
                  In this tutorial we will use our flight service and perform update operation in flightset.

Pre-requisites

  1. FLIGHTSET_UPDATE_ENTITY method implemented in sap backend flight service.
  2. SAPUI5 Application created.
  3. OData service (I am using flight service created in earlier tutorials)added to the created application and odata model is set.
Steps
  1. Our SCARR table before update is like below.We will update the entry with carrid AC.

  2. First put below code in our view.Here we will hardcode the flight details in a simple form and place a button below it.On press of the button we will update the entry through OData.


  3. Now our view will look like this.
  4. Add update logic inside onUpdate method of the view's controller.Copy paste below logic.Here we access the form values and pass it to oModel.update function.


  5. Press update button.You will get a success alert if updation was successful.Go to sap backend and check the table SCARR.Now you can see the carrier details of AC carrier is updated.
Note:If you are accessing the model from onInit method(this.getView().getModel();)of the controller you will get undefined error.Use var oModel = this.getOwnerComponent().getModel(); in onInit method
If you enjoyed this post, I’d be grateful if you’d help it spread by sharing.Thank you! See you soon

1 comments :

Powered by Blogger.