javascriptasynchronousdynamics-crmmicrosoft-dynamicsmicrosoft-dynamics-webapi

Save & Close Exiting Web Resource before Asynchronous Web API Call


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


Solution

  • 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.