cancel
Showing results for 
Search instead for 
Did you mean: 

Update OData Service

nitesh_jain3
Active Participant
0 Kudos

Hi all,

Is it mandatory to write a read operation in a Odata service which is mainly meant for change/update?

regards

Nitesh

Accepted Solutions (1)

Accepted Solutions (1)

ChandraMahajan
Active Contributor
0 Kudos

Hi,

it is not mandatory that you need to implement read operation. but it is good to implement it because when you want to test update operation in GW client, you can first execute read operation then copy response payload using "Use as Request" button and then do the required update in request and execute PUT operation. also you can then execute GET again to know if the update was successful.

But the answer is, it is not mandatory to write Read operation.

Regards,

Chandra

nitesh_jain3
Active Participant
0 Kudos

Hi Chandra,

Is there any other tool to generate the payload for the update without writing a read operation?

regards

Nitesh

ChandraMahajan
Active Contributor
0 Kudos

I am not aware about any other tool to generate payload. but if you observe the request payload, you will be able to create one for yourself.

for e.g. below is the query for PUT operation to update the contact record 1234.

/sap/opu/odata/sap/ZTRAIN_EMP_CONTACT_SRV/contacts('1234')

This will be the request payload. These are the minimum tags that need to be passed along with properties.

<?xml version="1.0" encoding="utf-8"?>

<entry xml:base="http://<host>:port>/sap/opu/odata/sap/ZTRAIN_EMP_CONTACT_SRV/"

        xmlns="http://www.w3.org/2005/Atom"

        xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"

        xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

  <content type="application/xml">

   <m:properties>

    <d:Empid>123</d:Empid>

    <d:Firstname>ABC</d:Firstname>

    <d:Lastname>XYZ</d:Lastname>

   </m:properties>

  </content>

</entry>

but this will become difficult once you have too many properties etc.

anyway is there any reason you do not want to perform Read operation?

Regards,

Chandra

Answers (3)

Answers (3)

dirk_roeckmann
Participant
0 Kudos

read is not mandatory but for a create or a query i would do a read too

nitesh_jain3
Active Participant
0 Kudos

Hi Chandra/Krishna,

At the client side when calling the update service call i am getting a CSRF token error. Is there any other way to generate the CSRF token than writing a read operation?

On the client side i am using Sencha touch which has an SAP Odata connector. Hopefully after providing the relevant details that should generate the correct payload.

regards

Nitesh

ChandraMahajan
Active Contributor
0 Kudos

Hi Nitin,

I believe your original question already got answered. for any further questions, you can create new thread and close this discussion. please refer   and

Thanks for understanding

Regards,

Chandra

nitesh_jain3
Active Participant
0 Kudos

Hi Chandra,

I do agree that my first question was answered.

However the answer to the first question led to other questions. As they are inter-related i think it will be helpful & time saving for others who have similar questions to get the complete picture in one SCN message/ discussion rather than have to look into multiple threads.

Coming to your question of not wanting to write a read operation. My OData service is to change the password of the sap netweaver gateway system. In this context the read operation is of no value. However considering the framework if i am forced to write one to generate the CSRF token it will only be a dummy.

regards

Nitesh

ChandraMahajan
Active Contributor
0 Kudos

Ok.

I guess you can use method setTokenHandlingEnabled(bTokenHandling?)

and set it to false. by default it is true.

Refer API documentation JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel

Regards,

Chandra




kammaje_cis
Active Contributor
0 Kudos

Yes Nitesh, As Chandra said it is not mandatory for Update. But it is required for 'Create', since framework tries to read the created entity/record.

Though it is not required, implementing 'read' helps a lot in testing and there is a easy way to do that. Just hardcode the values in the read method, so that the response for read is available at the client and 'use it as request'.

thanks

Krishna