web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Power Platform 2021 Wave 1 – My Favourite Features for Power Apps – Part 4

(0) ShareShare
ReportReport
Posted on by 18,054

Async OnSave events

In a model-driven app form, to do any validations on record save, we use OnSave event of the form. We bind the event handler function by directly adding it in form properties OnSave or by binding the handler function using addOnSave (formContext.data.entity.addOnSave). When the record is saved (user clicked on Save / Save&Close or auto-save was triggered or save triggered from code using formContext.data.entity.save / formContext.data.save / formContext.data.refresh(true…)), the OnSave handler function is called and we have to use the formcontext.geteventargs().preventdefault() block the default save, perform validations and then trigger another save. We also have to handle what happens after saved depending on how the Save was triggered. As you can see adding custom logic to OnSave event to perform any validation is not very straightforward and not a clean approach and performing any async calls makes it even more complicated.

With the release of 2021 Wave1, Async OnSave feature will allow a promise to be passed to perform validations and if the promise does not resolve within 10 seconds, the save will be blocked. This provide a lot more cleaner pipeline to hook into OnSave with a flexibility to perform complex validations. I have tried to do some tests on my trial instances but the feature is still not available on my environment. I will update this post with sample code once I had a chance to play with it.

Public Preview – Feb 1, 2021 | Early Access – N/A | General Availability – April 2021

What are Async OnSave events?

This provides the ability to create Async OnSave events. Async OnSave events will now wait when they provide a promise, and there is also a new timeout if the promise does not resolve within 10 seconds. If it does not resolve within 10 seconds, the save operation will be blocked.

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/events/form-onsave

Some useful links related to OnSave event

https://www.itaintboring.com/dynamics-crm/when-would-onsave-form-event-occur-in-model-driven-apps/

*This post is locked for comments

I have the same question (0)
  • LuHao Profile Picture
    40,892 on at
    RE: Power Platform 2021 Wave 1 – My Favourite Features for Power Apps – Part 4

    Hi Kokulan,

    Thanks for your sharing.

    Please request a community blog to post your blogs.

    community.dynamics.com/.../136.request-a-new-blog-or-blog-to-syndicate

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 76 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 55 Most Valuable Professional

#3
Anthony Blake Profile Picture

Anthony Blake 43 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans