cancel
Showing results for 
Search instead for 
Did you mean: 

OData no HTTP response for PUT/POST requests possible?

Former Member
0 Kudos

Hi Experts,

I'm implementing some calculation tool using UI5/OData/SAP NW Gateway. I have following problem which I can't get solved:

On a webpage there are three fields:

Field 1: Base Quantity (value=100)

Field 2: Input field in percent (value=20)

Field 3: Result field (value=20/100*100=20)

Field 3 should be calculated in the gateway/backend.

The problem is, I enter some percentage value in Field2, then I trigger an update OData request to the Gateway (PUT or PATCH).

In the gateway I calculate Field 3 on the base of the entry in Field 1 and 2. I write the result structure back to ER_ENTITY.

Question: Isn't it possible to pass a result set back to the client for an UPDATE in the HTTP respone? I don't want to trigger another GET request to fetch the result of the calculation.

Thanks a lot for your help in advance!

Cheers,

Thorsten

Accepted Solutions (1)

Accepted Solutions (1)

kammaje_cis
Active Contributor
0 Kudos

Hi Thorsten,

As per OData, an 'Update' need not return anything.

NW Gateway returns http status code '204' which stands for 'No content'. You can read more here.

http://www.odata.org/documentation/odata-version-2-0/operations/

Thanks

Krishna

Former Member
0 Kudos

Thanks Krishna!

do you have any suggestions on how to update dependent data In UI5?

My idea is to update dependent data within one update request. Afterwards i want to retrieve all the data using an expand.

Is there any way to trigger the GET request with expands and update the ODataModel the same time Without using a separate JsonModel?

The Api does not seem to offer this. I think i have to extend the ODataModel and do it on my own.

Thanks,

Thorsten

kammaje_cis
Active Contributor
0 Kudos

For updating dependent data, you have three options.

1. Issuing an update by association. Here the URI will point to the dependent entity and you update the main entity and dependent entity in separate requests.

2. Using Deep Insert. This is ideal for parent child relationships. Ex: Sales Order and Sales Order items. But as per OData you can only do a 'Create', not 'Update'. Though in ABAP, you can use it as an update request, but not recommended.

3. If you want to update main and dependent entity in one single call, you can think about using $batch of oData protocol. Batch also ensures the atomicness of data (update all or none).

Thanks

Krishna

Former Member
0 Kudos

Thanks Krishna,

that's very helpfull. I will try the $batch update.

In order to refresh the data in the UI I want to trigger a GET request with expands. The

RefreshAfterChange property is disabled for my ODataModel. I just want to refresh on demand.

Do you know how I can push the result from a GET request into the ODataModel?

I ask because e.g. ODataModel.read/OData.read do not write the result back into the model.

Any idea?

Thanks a lot!

Thorsten

kammaje_cis
Active Contributor
0 Kudos

I have some working knowledge on SAPUI5, but never had to update oDataModel. May be if you can explain what you are trying to do, then there might be alternative ways.

Former Member
0 Kudos

Hi Krishna,

I'm doing following:

I have three entities which relate to each other as follows:

EntityHeader

-> EntitiySub

---> EntitySubSub

When I update a Property of EntitySubSub, the EntitySub and EntityHeader must be recalculated and retrieved to the UI.

First I send an update: ODataModel.update for EntitySubSub. Because this does not return a ResultSet I have to request the data for EntitySubSub, EntitySub and EntitiyHeader with another GET request manually.


I found folowing solution, the ODataModel has a (private?) method _importData. As our model is derived from the ODataModel, I have implemented a refreshBindings method as follows:

     refreshBinding : function(aPath, oContext, bAsynchronous, fnSuccess, fnError)
     {
          var that = this;
          var aBatchOperations = new Array();
          var sFullPath = "";
          
          if (!bAsynchronous)
               bAsynchronous = false;

          for ( var key in aPath)
          {
               sFullPath = this.resolve(aPath[key], oContext)
               if (sFullPath == "/") sFullPath = oContext.getPath();
               aBatchOperations.push(this.createBatchOperation(sFullPath, "GET"));
          }

          this.addBatchReadOperations(aBatchOperations);

          this.submitBatch(
                    function(oData, response)
                    {
          
                         for ( var request in oData.__batchResponses)
                         {
                              that._importData(oData.__batchResponses[request].data);
                         }
          
                         sap.ui.getCore().getModel().updateBindings(true);
          
                         if (fnSuccess)
                              fnSuccess();
          
                    },
                    function(oError)
                    {
                         if (fnError)
                              fnError(oError);
                    }, 
                    bAsynchronous);

     }

The call looks as follows:

oModel.update(oEvent.oSource.getBindingContext().getProperty().......);
oModel.refreshBinding(["/", // < EntitySubSub
                                "EntitySub",
                                      "EntitySub/EntityHeader"
],
oEvent.oSource.getBindingContext(), false);

Here you can pass the relative paths you want to update within the array aPath. A BatchRead is done for these entities. Afterwards I import the retrieved data into my ODataModel. I'm doing it that way because I didn't get it working with $expand.

When using the ODataModel.read with $expand I receive a nested ResultSet which I imported to the ODataModel. Then the problem is when I update some Property in this result set later on using ODataModel.update, then the nested structure is sent to the gateway, this request errors out. AFAIK it should work with the submitChanges method because in its code the nested data is removed before the update explicitly.

Maybe somebody forgot to do it in ODataModel.update too.

kammaje_cis
Active Contributor
0 Kudos

You said "When using the ODataModel.read with $expand I receive a nested ResultSet which I imported to the ODataModel."

I think it would be wrong to import the ResultSet into the oDataModel since it has nested structure. Rather the child entries should have gone as entityset values.

I think UI5 forum is the right one to discuss this question.

Thanks

Krishna

Answers (1)

Answers (1)

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Kudos

Is your issue resolved?

Rgrds,

Jitendra