question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Odata.v4.OdataModel - hasPendingChnages error after failed submitChanges

See original GitHub issue

I use Odata V4 and I check if submitBatch method has been failed by checking the result of hasPendingChanges method.

this.getModel().submitBatch(BATCH_ID).then(function () {
                var bHasErrors = this.getModel().hasPendingChanges(BATCH_ID);
                if (bHasErrors) {
                    this._displayError();
                } else {
                   ...
            }.bind(this)).catch(function () {
                ...
            }.bind(this));
        },

If the result of hasPendingChanges is true, then batch failed(f.e. ‘such value already exists in database’) and error message appears. But after fixing duplicated value and resubmit the same error occurs.

The same issue described on SAP tutorials GitHub page, but it is still in process…

I tried to delete my batches(sGroupId = “TaskDetailBatch”) with array of bathes, but this array always updates the previous condition:

image

P.S. The same isue was not resolved here

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
uhlmannmcommented, Apr 15, 2020

Hi @YahorStsefanovich ,

I do not get why you need another updateGroupId. I would expect something like the following: Create case

  • The new context is created via ODataListBinding#create. (The list binding would preferably be the list binding you use for showing the task list.)
  • This new context is set as the binding context of the view for editing/creation.
  • When the user saves, submitBatch is triggered. The POST can either be successful (no pending changes, created promise is resolved) or not (the response to the POST should bear messages explaining why the POST was rejected, cf. Server Messages in OData V4 Model). The view would only be left if the created-Promise is resolved / there are no pending changes. (This depends on the design of the application. It could also have a central save and the view could be left without saving.) The important part with the failing save is that the backend provides understandable messages, preferably with a target to highlight the fields with the wrong input.
  • A Cancel/Delete button would allow the user to remove the transient context again. (With a global save, Cancel would not make much sense here as resetChanges would act globally on all changes.)

Edit case

  • The existing context is, e.g., the selected context of a list binding.
  • The context is set as the binding context of the view for editing/creation.
  • And then it works identically to the create case for the user.

Using several updateGroupIds does not seem like a good idea. Changes in different updateGroups lead to several batch requests. Is this really intended?

Best regards Mathias.

1reaction
uhlmannmcommented, Apr 6, 2020

Hi @YahorStsefanovich ,

I guess @vfweiss has already provided a possible solution for the create scenario.

In general, the promise of submitBatch is only rejected if the batch request itself has failed. The consequence is that this promise does not tell if changes were successfully persisted in the backend. However, it provides the point in time when an application could check itself. hasPendingChanges, which exists at context, binding and model with the respective scope, is one option.

I am not sure I understood your case correctly. You are trying to delete a number of records? What is the purpose of putting them into different batch requests?

Let me add two comments:

  1. Changing requests are sent in changesets within the batch request. A changeset represents a logical unit of work and is either persisted as a whole or not at all. So far, changing requests are typically put into the same one changeset by the V4 model. Furthermore, the processing of the batch request will stop once a request has failed. (The preference continue-on-error is not used by the V4 model. Also it must not be used when using v4.Context#requestSideEffects.)

  2. With a backend that provides language dependent, understandable messages, see also Server Messages in OData V4 Model, it should be sufficient to display the messages from the message model to the user. It would then not be required to understand in application code what failed but only that the save was not successful.

Best regards Mathias.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sap.ui.model.odata.v4.ODataModel - API Reference - Demo Kit
Valid values are 'API', 'Auto', 'Direct' see sap.ui.model.odata.v4. ... If a back-end request fails, the 'dataReceived' event provides an Error in the ...
Read more >
Creating an Entity
As long as the list binding has a transient entity, ODataListBinding#hasPendingChanges returns true and the following methods of ODataListBinding raise an error ......
Read more >
oData Model submitChanges error callback function not ...
I would like to know when I use the submitChanges of sap.ui.model.odata.v2.ODataModel , and have a success and error callback function.
Read more >
SAPUI5 for dummies part 5: A complete step-by-step exercise
Update OData model record. Here comes the core part of our exercise. When the user clicks the Save button we're going to execute...
Read more >
[SAPUI5] Get and set properties of a binded model and submit ...
hasPendingChanges ( ) ) {. MessageToast . show ( "Nothing to do!" ) return. } // Now submit your changes. oModel . submitChanges...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found