1

I am building a fairly complex web resource that uses the Dynamics Web API to read/write data to Dynamics.  I have a situation where I need to create an entity that requires the ID from two other entities that I need to create.  To do this, I use two asynchronous calls to create the two entities and then I use the data returned from the two asynchronous calls to fill in data records in my third entity I create.  The problem I am having is that when someone clicks Save & Close, the Close occurs before my asynchronous calls complete.  The first create call is sent and then the Close occurs without the second or third create occurring.  I also fear that on Save, I most likely have a race condition with my Web API calls where if someone clicked Close fast enough after Save all the data may not be saved.  Is there any way to get around this problem with asynchronous calls?

Some possible solutions I have explored that either don't work or I don't really like

  • Disable Save & Close (possibly still have a race condition when doing Save and then Close)
  • Batch Processing (not sure if this would even work, but way more difficult if it does)
  • Use timeouts to pause close (don't think this will work)
  • Cancel Close & reissue Close when save is complete (there has to be a better way, right?)
Tim Hutchison
  • 3,483
  • 9
  • 40
  • 76

2 Answers2

0

Basically I don't want to stop user for my internal operations, that's going to be a bad user experience. Still if Business agrees, you can have a custom Save & Close button or prevent default of OOB Save & close, open a custom HTML webresource showing progress bar while doing all the Async WebAPI calls inside popup till we get status 200 for everything, then close the progress popup.

Another route is Classic Async Plugin to achieve it. Even Action is available. Unlike Organizationdata service, WebAPI endpoint can help you in server side code also.

-1

There are two solutions here that seem to work.

  1. Remove the Save & Close button.
  2. Add custom button for Save & Close.

We ended up using option 1, but may at some point circle back to try option 2. We also added a pop up box to show a success/fail message when the save is complete to get the user used to waiting for the pop up box before navigation away from the page.

Tim Hutchison
  • 3,483
  • 9
  • 40
  • 76