On a model-driven form, an OnSave handler must call a Dataverse custom API to check for duplicate contracts and the save must wait for that server call to finish before it proceeds. Which implementation follows the supported Client API pattern?
Select an answer to reveal the explanation.
Short Explanation
A save is like a door closing: if you're still on the phone when it shuts, you're too late. Return a promise from an async OnSave handler with the app setting on, and the form holds the door until your server check comes back.
Full Explanation
The OnSave event supports asynchronous handlers. When the Async onSave handler feature is turned on in the app's settings and a handler returns a promise, the platform waits for that promise to settle before saving. If several calls are needed, they are combined with Promise.all into one returned promise, because the event waits for one promise per handler, and each promise is subject to a timeout, documented as 10 seconds, unless the handler calls disableAsyncTimeout before its first asynchronous call. The documentation also states that preventDefault can only be used synchronously, so calling it in a callback of an unreturned promise is too late: the save has already proceeded. PostSave runs after the save has completed and cannot cancel it; reacting there would require a separate compensating update. Checking in OnLoad is stale by design, because the user may change the data after the form opens, and another user may create a duplicate in the meantime. Exam caveat: a client-side check improves the user experience but does not enforce the rule for imports or API callers; a plug-in or a uniqueness constraint such as an alternate key provides enforcement. Operational check: enable the setting, add a deliberate delay to the custom API call, and confirm the save waits and the save outcome reflects the check's result.