cancel
Showing results for 
Search instead for 
Did you mean: 

update data in ui5 through sap netweaver gateway

0 Kudos

Hi experts!!

I am trying to update the data in my table in UI5 through sap netweaver gateway service .

I redefined the method for update but i am not able to hit my service through UI5.

this is the way i am defining my service path and assigning it to the model.

   var service = "/sap/opu/odata/sap/z01_customer_srv_01/";

   var oModel = new sap.ui.model.odata.ODataModel(service, true, "", "");

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

this is the way i am fetching the changed data from the cells of the table and storing it in a structure oData

        var oData = {} ;

        var selectedRow = oTable.getRows()[i];

        oData.number = selectedRow.getCells()[0].getValue();

        oData.name = selectedRow.getCells()[1].getValue();

        oData.weight = selectedRow.getCells()[2].getValue();

        oData.city = selectedRow.getCells()[3].getValue();

        oData.country = selectedRow.getCells()[4].getValue();

        oData.joindate = selectedRow.getCells()[5].getValue();

        oData.salary = selectedRow.getCells()[6].getValue();

        oData.currency = selectedRow.getCells()[7].getValue();

and now calling the update method of the service and assigning the value of keyfield i.e. in oData.number.

sap.ui.getCore().getModel().update("/cust_det('" + oData.number + "')"), oData , null, function()

but i am getting an error while running it in browser

Uncaught TypeError: Cannot read property 'context' of undefined

please help me out through this

Accepted Solutions (0)

Answers (3)

Answers (3)

scott_stefanich
Active Participant
0 Kudos

Hello Rachna,

Create an object for the optional OData Update parameters, then pass the object after the update path string and OData object. For example,

var mParameters = {

  success : function(){

    console.log("OData Update Success");

  },

  error : function(){

    console.log("OData Update Error");

  }

};

sap.ui.getCore().getModel().update("/cust_det('" + oData.number + "')", oData , mParameters );

Regards,

Scott

Former Member
0 Kudos

Hi Rachna,

I think there is some mismatch with your brackets in the following line syntax:

All the parameters of the update function should be inside its circular bracket like :-

sap.ui.getCore().getModel().update("/cust_det('" + oData.number + "')", oData , null, function() { } )

instead of:

sap.ui.getCore().getModel().update("/cust_det('" + oData.number + "')"), oData , null, function()

Let me know.

Thanks!

0 Kudos

Hi Utkarsha,

I tried this, the code of my javascript got executed with this but my method of netweaver did'nt get triggered .

Thanks !

Former Member
0 Kudos

Hello Rachna,

I think the URL you have created for updating is not matching with the actual :

"/cust_det('" + oData.number + "')"


In the Gateway, you can try executing this URL, giving the actual parameters. I am guessing the value of the parameter is not matching with the entity type you have given in the gateway.

Also, try checking out this thread: http://scn.sap.com/thread/3298640

Let me know.

Thanks!

0 Kudos

Hi Utkarsha,

I tried executing the URL in the gateway its working fine.

The value which i am fetching in oData.number is the same which i am sending through the URL in the gateway. But it's not working.

If there's something which i can try to solve this , let me know.

Thanks!

Former Member
0 Kudos

Hi Rachna,

Could please confirm if you have added the sap.ui.table library in your bootstrap?

Also, please let me the value when you try to print at the console:

sap.console (oData.number);

Thanks

0 Kudos

Hi Utkarsha,

Yes i have added the library in the bootstrap and i m able to fetch the value of oData,number as i have tested through alert.

i am even performing delete operation which is working fine.

issue is with update and create.

is there some different way also to post the data ???

please let me know if it is.

Thanks