Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Unanswered

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

Posted on by 18,048

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

  • LuHao Profile Picture
    LuHao 40,844 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

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,768 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,985 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans