user7142812
user7142812

Reputation: 11

D365 Navigate away from record without showing unsaved changes dialog

We are implementing a custom duplicate detection handler off the save of a new contact record in D365. It is being done via Javascript. In the JS OnSave method, we stop the default save action and do some checks via WebAPI to determine whether this may be a duplicate or not. If no potential duplicates are detected, we manually call the save again in JS. If some potential duplicates are detected, we display a HTML web resource listing the possible duplicates.

What we are trying to achieve is that the user can double-click on one of the potential duplicates and we will navigate them directly to that other contact record without saving the record that the user was keying in originally. We are using the Xrm.Navigation.openForm command to achieve this.

The problem is that by default this displays a popup to the user asking them if they wish to save their changes first before leaving the page. Once they have interacted with this dialog -> it does navigate them to the other record but clearly this is a non-runner in terms of useability (and they can still choose to save the record first anyway). Is there any way for me to achieve the programmatic navigation to another CRM contact record whilst already being in a CRM contact form in creation mode? I can't seem to find anyway to hide that default dialog.

Upvotes: 1

Views: 957

Answers (2)

andrej jakubicka
andrej jakubicka

Reputation: 11

i was dealing with very similar issue

my workaround was to ignore all attributes on save

var attributes = formContext.data.entity.attributes.get();
        for (var i in attributes) {
            attributes[i].setSubmitMode("never" /* XrmEnum.SubmitMode.Never */);
        }

call this function before you navigate away from the form

Upvotes: 1

Malachy
Malachy

Reputation: 392

The easiest solution in my opinion would be to:

  1. Call: Xrm.Page.data.refresh();
  2. In the success callback navigate away

Because you have refreshed the page - there should be no dirty fields and the navigate away will work.

If you want to avoid the refresh call the alternative solution would be to 1:

  1. Retrieve the Dirty Fields
  2. For each field call setSubmitMode("never") - you should then be able to navigate away

Upvotes: 0

Related Questions