One of our current projects is the migration of an onPrem Dynamics 365 to the Cloud. Part of that is refactoring existing JavaScript implementation. The current implementation had an onSave function which prevented the save process based on a call to the WebAPI. It took me some time to migrate the function, therefore I thought it might be interesting for others to know how to write an async onSave preventDefault with external call.
Async onSave preventDefault with external call is a technique used to prevent a form from submitting when a user clicks a submit button. This technique involves using the preventDefault() method to stop the form from submitting, and then making an asynchronous call to an external API to check the data entered in the form. If the data is valid, the form can then be submitted. This technique is useful when you need to perform some kind of data validation before allowing the form to be submitted.
Async onSave preventDefault with external call
Xrm.WebApi (Client API reference) in model-driven apps - Power Apps | Microsoft Learn
preventDefault (Client API reference) in model-driven apps - Power Apps | Microsoft Learn
preventDefaultOnError (Client API reference) in model-driven apps - Power Apps | Microsoft Learn
Oct 12, 2017 — When you want to cancel a save event in CRM Dynamics 365 Customer Engagement, you use “preventDefault()” to block the save operation.
Feb 16, 2023 — I ran into an issue recently where I was trying to intercept document link clicks and route them to an external browser window in the Windows ...
I'm having some strange behavior with the the OnSave e.preventDefault() event firing correctly when inside an ajax call in my Grid editor.
Yes, it is totally possible to call preventDefault() in an async event handler function . You only have to ensure to make the call before ...
We would then call preventDefault to stop the save. Currently we have no way of doing this because the onSave event is expected to return synchronously.