Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

onsave handler: preventDefault() does not cancel form save in Sales Hub

(0) ShareShare
ReportReport
Posted on by 10

We have a form, for the appointment entity, for which we've registered an onsave-handling function. The intent is to display a confirmation dialog to the user when certain fields have been modified. To do this, the function cancels the initial save operation, then if the user clicks to confirm, it performs a second save operation asynchronously (with a check so that the function is not triggered again).

The code is roughly:

let confirmDialogIsOpen = false;

async function confirmSave(saveContext) {
if (confirmDialogIsOpen) {
// Allow save event from user confirmation
return;
}

confirmDialogIsOpen = true;

// Prevent save operation before async-break
saveContext.getEventArgs().preventDefault();

// ***Function synchronously returns here***

// Get result for confirmation dialog
const userHasConfirmed = await saveUserConfirmation();

if (userHasConfirmed) {
// Perform second save operation
saveContext.getFormContext().data.entity.save();
}

confirmDialogIsOpen = false;
}

This works correctly in the old-style default hub, and in Customer Service Hub. However, in Sales Hub the `.preventDefault()` call seemingly has no effect. No exception is thrown, and when the function synchronously returns before the async break, the save is performed and the form is soft-reloaded.

Has anyone else experienced/worked around this? Is it a known issue?

  • Toby Dimmick Profile Picture
    Toby Dimmick 10 on at
    RE: onsave handler: preventDefault() does not cancel form save in Sales Hub

    Thanks for the references - however these suggestions don't solve the problem.

    - We already have auto-save disabled for all forms.

    - We're calling .getEventArgs().preventDefault() from the passed-in execution context, not Xrm.Page.Context.

  • LuHao Profile Picture
    LuHao 40,876 on at
    RE: onsave handler: preventDefault() does not cancel form save in Sales Hub

    Hi Toby,

    Please refer to

    community.dynamics.com/.../965940

    docs.microsoft.com/.../manage-auto-save

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans