Hi everyone,
I want to apply a validation on save and close button, if it returns false, want to prevent to close the form. How can I achieve? Any idea?
Thanks in advance,
*This post is locked for comments
Hi,
Try with this , attach the function in the onsave event ,dont forget to pass execution context .
function preventSaveAndClose(econtext) { //Do your validation here var isValid =false; // Set the false here if validation failed var eventArgs = econtext.getEventArgs(); if ((isValid == false ) && (eventArgs.getSaveMode() == 70)) { eventArgs.preventDefault(); } }
You can find more details here -
https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg509060(v=crm.8)
I have tried this one but it does'nt prevent to close the from it's only prevent to save the form.
Sorry I have not tried , check with this adding return false statement -
function preventSaveAndClose(econtext) {
//Do your validation here var isValid =false; // Set the false here if validation failed var eventArgs = econtext.getEventArgs(); if ((isValid == false ) && (eventArgs.getSaveMode() == 70)) { eventArgs.preventDefault(); return false; } }
Pass the context/executionobject to your onSave function and prevent saving with
executionObj.getEventArgs().preventDefault();
Edit: sorry, didn't refresh the tab before answering
unfortunately, it doesnt work :(
After much research, the only solution I've found is to edit the ribbon to override the behavior of the Save and Close command itself.
See the post from Dan Overton here: https://community.dynamics.com/crm/f/117/t/155316
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
HR-09070029-0 2
UllrSki 2
ED-30091530-0 1