Configuring Async Timeout for Model-Driven Forms OnSave Dialogs
Image Source: Shutterstock.com
Model-Driven App
Sep 29, 2023 5:48 AM

Configuring Async Timeout for Model-Driven Forms OnSave Dialogs

by HubSite 365 about Diana Birkelbach [MVP]

Dianamics PCF Lady | Microsoft MVP | Blogger | Power Platform Community Super User | 👩‍💻 Dynamics 365 & PowerPlatform Developer | ORBIS AG

Citizen DeveloperModel-Driven AppM365 Hot News

Master asynchronous OnSave events in Model-Driven Forms with the Microsoft Disable Async Timeout feature - Save smarter!

Diana Birkelbach [MVP] talks in her blog post about disabling the Async Timeout in Microsoft's Model-Driven Forms onSave events and integrate dialogs into the process. Until recently, the execution of asynchronous code was not possible for these events. Before saving a record, a manual pause in the saving process was necessary to launch requests. It then often resulted in the rejection of any formContext.data.save() attempts linked to standard ribbon commands.

This process sparked a heated debate around the issue. A solution came up a few years back with the "Async OnSave". This feature gave an alternative to customize for the onSave events of each Model-Driven Form.

This change developed a mechanism for users to return promises from the onSave handler. However, the handler is designed with a very strict timeout limit of ten seconds. While this proves to be beneficial in most cases, it becomes challenging when it involves user interaction. For example, asking a user to confirm the saving action.

In the guesswork for the onset of this limitation's solutions, the spotlight has been on "disableAsyncTimeout" feature documented before, yet its functionality failed in the past. The author articulates her surprise at learning recently that it was finally working, though the exact announcement or commencement date remains a mystery.

The author moves on to describe the process for tapping into this feature in an onSave event-using scenario. Initially, apply disableAsyncTimeout inside the onSave handler, then if the user opts for 'no', activate the ‘preventDefault’ function to abandon the saving operation. Although enabling autosave is usually helpful, the author suggests disabling it in this case to stop the bombardment of confirmation dialogs.

Grounding her information with practical applications, the author provides an example of using the process to save changes. The user sees a confirmation dialog box, and although this initially triggers a platform error due to the Promise timeout reaching ten seconds, it prevents the data from saving only once the user confirms or rejects the action.

General Overview of Model-Driven Form's Async Timeout

Model-Driven Form's Async Timeout feature is crucial to provide flexibility to developers working with onSave events. The model's sophisticated features help prevent autosave and give users more control over their actions. Users can access developer features to enable or disable settings depending on their needs. As the technology continues to evolve, more advanced features are anticipated to make Working with Model-Driven Form a seamless experience.

Read the full article Disable Async Timeout for Save Events in Model-Driven Forms – Show Dialogs in OnSave

Model-Driven App - Configuring Async Timeout for Model-Driven Forms OnSave Dialogs

Learn about Disable Async Timeout for Save Events in Model-Driven Forms – Show Dialogs in OnSave

The OnSave event in Model-Driven forms erstwhile didn't allow for the execution of asynchronous code. To make requests prior to saving a record, the saving process had to be temporarily halted, the necessary requests made, and then saving procedure reinitiated. However, this method posed various issues, especially rejecting any formContext.data.save() attempts, executed behind some standard ribbon commands.

In response to such issues, Microsoft introduced the "Async OnSave" feature some years ago. This feature provides an option for setting each Model-Driven Application. With it, promises can be returned from OnSave handlers. However, the Promises returned from the save handler have a time limit of 10 seconds, often making it insufficient for user interaction, which typically is an asynchronous process.

Yet, there is a documented feature that allows for the disabling of this timeout, termed as "disableAsyncTimeout", but its functionality had been a longstanding issue. Recently, it has been observed that this feature has started working, although it's not clear when and if an announcement regarding this had been made. This feature allows us to demonstrate a confirmation dialog in the OnSave event.

What this means is that all applications using the Model-Driven system can now implement an OnSave handler that will first allow the user to decide what to do. The first step is to call the "disableAsyncTimeout". This application applies on event arguments so it needs to be put inside the OnSave handler. If the user chooses "no", the "preventDefault" can be called to stop saving.

It's important that autosave be disabled on the form, as failure to do so will result in the user getting confirm dialogs every 30 seconds. If the changes are attempted to be saved, a confirmation dialog will be displayed. Also, the platform, irrespective of the Promise timing out after 10 seconds, will pause the save process until the user confirms or denies. On the selection of "Cancel", the data won't be saved and if "OK" is selected, the data is saved.

If autosave is set and no save action is taken, it activates every 30 seconds, but the dialog wouldn't be displayed as it would have been prevented. Only error messages would be visible in the console. However, data can still be saved even if "OK" is chosen post the timeout being elapsed. This development signifies a significant stride in taking control of Promise timeout within save events.

Therefore, knowledge of this change is integral for users of the Model-Driven system, as this affirms enhanced control over Promise timeout within saving events. It also underscores the incessant effort by Microsoft to ameliorate user experience and increase the efficiency of their products.

More links on about Disable Async Timeout for Save Events in Model-Driven Forms – Show Dialogs in OnSave

Disable Async Timeout for Save Events in Model-Driven Forms
Mar 23, 2023 — Show a confirm dialog in OnSave event​​ This applies on event arguments, so we need to place it inside the OnSave handler. If the user says “no”, ...
model-driven app Client API : disableAsyncTimeout issue
May 6, 2022 — The issue is about being able to show a confirm dialog in "onSave" event. The Confirm is async, and it's great that the OnSave now waits for ...
Form OnSave event (Client API reference) in model-driven ...
Jul 26, 2023 — To make sure the async operation waits for the promise to resolve, use the disableAsyncTimeout method. You must call disableAsyncTimeout before ...

Keywords

Disable Async Timeout, Save Events, Model-Driven Forms, Show Dialogs OnSave, Model-Driven OnSave Disable, Async Timeout Save Events, Disable Timeout Model-Driven, OnSave Dialogs Model-Driven, Save Events Disable Async, Async Dialogs in Model-Driven Forms.