cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Odata Model V4 SubmitBatch does not affect "hasPendingChanges"

former_member260921
Participant
0 Kudos

Data has been changed in the form and submitBatch has successfully updated the server data. oBinding.hasPendingChanges()
should be false but stays true even though the batch has been successfully submitted.

Why is oBinding.hasPendingChanges() still returning true when it should be false?

groupProperties.Submit can be either API or Auto and the issue persists

Code:

var oBinding = this.byId("idMainTable").getBinding("items");
var oThis = this;

var fnSuccess = function() {
oBinding = this.byId("idMainTable").getBinding("items");
var bChangedAfter = oBinding.hasPendingChanges()
//bChangedAfter should be = false but is still true!! Why?
//The data has been updated correctly at the server.

}.bind(oThis);

var fnError = function(oError) {
//handle error
MessageBox.alert(oError.message);

}.bind(oThis);


if (oBinding.hasPendingChanges()) {
oThis.getView().getModel().submitBatch("ladderList").then(fnSuccess, fnError);

} else {
//Do nothing - no changes to Submit

}

maheshpalavalli
Active Contributor
0 Kudos

can u check if the request is successful from the network tab?, it might show 200, but go inside and check if there are any errors in the responses.

former_member260921
Participant
0 Kudos

Mahesh,

Thanks. The request is successful in the the network tab but the hasPendingChanges is not reset to false.

Mel

maheshpalavalli
Active Contributor
0 Kudos

mel.dodd4

Ideally, it shouldn't happen. My only guess is that in the network tab, it is successful(200), but inside the response body you might be having errors, if that is not the case, then it's a weird behaviour 😞
former_member260921
Participant
0 Kudos

Thanks, Mahesh. It does seem wierd.

Accepted Solutions (0)

Answers (1)

Answers (1)

ThorstenHoefer
Active Contributor
0 Kudos

Hi,

You can check the pending changes with the getPendingChanges() method.

Maybe you need to rebind the table?

https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui.model.odata.v2.ODataModel%23methods/getPendingChan...

You should also check the documentation about #hasPendingChanges(). Do you modify the model with create, update or remove? In this case you should set the optional parameter bAll to true.

hasPendingChanges

Checks if there exist pending changes in the model.

By default, only client data changes triggered through: #createEntry #setProperty are taken into account.

If bAll is set to true, also deferred requests triggered through: #create #update #remove are taken into account.

hasPendingChanges(bAll?) : boolean

Update:

In ODataV4 hasPendingChanges has the parameter of the group ID. In Your case, it should be: "ladderList"

https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui.model.odata.v4.ODataModel%23methods/hasPendingChan...

hasPendingChanges(sGroupId?) : boolean

A group ID as specified in sap.ui.model.odata.v4.ODataModel, except group IDs having sap.ui.model.odata.v4.SubmitMode.Direct; if specified, only pending changes related to that group ID are considered (since 1.70.0)

former_member260921
Participant
0 Kudos

Hi Thorsten,

Thank you very much for your suggestions. As you noticed I am using oDataModel.V4. I have tried supplying the GroupId but it does not seem to change anything. The table binding itself is already associated with that GroupID ("ladderList") but the problem is the same whether or not I have "ladderList" as a paramter to hasPendingChanges.

If I edit a column in the table hasPendingChanges correctly returns true.

Then I call oThis.getView().getModel().submitBatch("ladderList").then(fnSuccess, fnError) which succeeds. The data is updated on the server and reply is 200 in the Network pane.

But hasPendingChanges is still true and should be false since the server is updated.

I am wondering now about Odata V4. And whether I should revert to Odata V2. V4 seems to still have some limitiations and issues although does have some new features. Do you know if people are generally happy with V4?


Thanks again for your help.

Mel

ThorstenHoefer
Active Contributor
0 Kudos

Hi Mel,

I found the List binding Parameter $$updateGroupId.

https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui.model.odata.v4.ODataModel/methods/bindList

Maybe you need to add this parameter to your binding?

Like this?

https://embed.plnkr.co/plunk/qatUyq

this.getView().bindElement({ 
    path: `/People('${decodedUserName}')`
  , parameters: { $$updateGroupId: batchGroupId }
  , events: { dataRequested: () => this.byId("page").setBusy(true), 
              dataReceived: () => this.byId("page").setBusy(false) 
             }
  });
former_member260921
Participant
0 Kudos

Hi Thorsten,


Thanks again for your comment. Unfotrunately I have already set the $$updateGroupId for the Binding.

<Table id="idMainTable" inset="false" mode="SingleSelectMaster" includeItemInSelection="false" selectionChange="onSelectionChange"
items="{path: '/UDO_K2P_APRV_LADDER',
parameters: {$$updateGroupId : 'ladderList', $orderby : 'Code'},
events: {dataReceived : '.onDataReceived', change: '.onDataChange'}
}" width="500px" >