Skip to Content
Author's profile photo Jibin Joy

SAP Netweaver Gateway CRUD Operation using SAPUI 5

Based on document Sample UME Application using SAPUI5 and SAP Gateway – Part II

I like to Update code for the sapui5 1.8.4

For Update

once model is set with service url …….

       var oModel = new sap.ui.model.odata.ODataModel 

                                                  (http://gwserver.com:8000/sap/opu/odata/sap/Z_UI5_USER_MAINT_CM/);     

              sap.ui.getCore().setModel(oModel); 

use oModel update method

.update(sPath,oContext,oData,fnSuccess,fnError,bMerge);

where

* Trigger a PUT/MERGE request to the odata service that was specified in the model constructor.

* @param {String} sPath A string containing the path to the data that should be updated.

*                                                                       The path is concatenated to the sServiceUrl which was specified

*                                                                       in the model constructor.

* @param {Object} [oContext] If specified the sPath has to be is relative to the path given with the context.

* @param {object} oData data of the entry that should be updated.

* @param {function} [fnSuccess] a callback function which is called when the data has

*                                                               been successfully updated.

* @param {function} [fnError] a callback function which is called when the request failed. The handler can have the parameter: oError which contains

* additional error information.

* @param {Boolean} [bMerge=false] trigger a MERGE request instead of a PUT request to perform a differential update

   there is small problem in the document.

the parameter sequence mentioned in document is

   sPath,oContext,oData,fnSuccess,fnError,bMerge

but in the code it is

  sPath,oData,oContext,fnSuccess,fnError,bMerge

oModel.update(‘z_ui5_user_maintCollection(‘AGAMPA’)‘,Odata);

________________________________________________________________________

if the XSRF token is disabled in SAP Gateway we have to pass the header X-Requested-With=XMLHttpRequest based on http://help.sap.com/saphelp_gateway20sp03/helpdata/en/e6/cae27d5e8d4996add4067280c8714e/frameset.htm

we can have add X-Requested-With in the Model

oModel.oHeaders[“X-Requested-With“] = “XMLHttpRequest”

_______________________________________________________________________

Other  Operation

For Create

* Trigger a POST request to the odata service that was specified in the model constructor.

* @param {String} sPath A string containing the path to the collection where an entry

*                                                                       should be created. The path is concatenated to the sServiceUrl

*                                                    which was specified in the model constructor.

* @param {Object} [oContext] If specified the sPath has to be is relative to the path given with the context.

* @param {object} oData data of the entry that should be created.

* @param {function} [fnSuccess] a callback function which is called when the data has

*                                                               been successfully retrieved. The handler can have the

*                                       following parameters: oData and response.

* @param {function} [fnError] a callback function which is called when the request failed. The handler can have the parameter: oError which contains

.create(sPath,oContext,oData,fnSuccess,fnError)

For Batch

http://scn.sap.com/community/developer-center/front-end/blog/2012/11/18/gateway-batch-calls-from-sapui5

For Delete

* Trigger a DELETE request to the odata service that was specified in the model constructor.

* @param {String} sPath A string containing the path to the data that should

*                                                    be removed. The path is concatenated to the sServiceUrl

*                                                    which was specified in the model constructor.

* @param {Object} [oContext] If specified the sPath has to be is relative to the path given with the context.

* @param {function} [fnSuccess]  a callback function which is called when the data has

*                                                               been successfully retrieved. The handler can have the

*                                       following parameters: oData and response.

* @param {function} [fnError] a callback function which is called when the request failed. The handler can have the parameter: oError which contains

* additional error information.

.delete((sPath,oContext,fnSuccess,fnError))

Regards,

Jibin Joy

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Kell Vagtholm
      Kell Vagtholm

      Hi

      This is rougly what is also found in JsDoc.

      Can anyone from SAP please explain the different formats avaialable for oData?

      Also what and how to handle the oError object?

      It would be nice with some useful examples for each case uwing UI5 to Gateway (directly).

      Finding info on this is very tedious - in fact not possible at all.

      Best regards,

      Kell Vagtholm