Dynamics 365 v9.0 – Xrm.Navigation namespace methods – Part 1

Hello everyone,

Dynamics 365 v9.0 has introduced Xrm.Navigation namespace under Xrm object. It has a mix of new methods and old methods moved from Xrm.Utility.

Following is the list:

Dynamics 365 v9.0 Comments
openAlertDialog  Deprecated Method: Xrm.Utility.alertDialog
openConfirmDialog  Deprecated Method: Xrm.Utility.confirmDialog
openErrorDialog  Introduced in v9.0
openFile  Introduced in v9.0
openForm   Deprecated Methods:
Xrm.Utility.openEntityForm
Xrm.Utility.openQuickCreate
openUrl    Introduced in v9.0
openWebResource   Deprecated Method:

In this blog post, I would like to discuss about the new features added in openAlertDialog and openConfirmDialog methods.

Prior to v9.0:

Syntax:

Xrm.Utility.confirmDialog(message,yesCloseCallback,noCloseCallback)
Xrm.Utility.alertDialog(message,onCloseCallback)

Sample Code:


Xrm.Utility.confirmDialog("Are you sure you want to approve this request?",
//Confirm Dialog Success Callback
function () {
Xrm.Utility.alertDialog("Request Approved Successfully",
//Alert Dialog Ok Button Callback
function () {
//
});
},
//Confirm Dialog Close Callback
function () {
Xrm.Utility.alertDialog("Request Aborted",
//Alert Dialog Ok Button Callback
function () {
//
});
});

Result:

v9.0:

Syntax:

Xrm.Navigation.openConfirmDialog(confirmStrings,confirmOptions).then(successCallback,errorCallback);
Xrm.Navigation.openAlertDialog(alertStrings,alertOptions).then(closeCallback,errorCallback);

Following is the rewritten code for v9.0 for showing confirm and alert dialogs using openConfirmDialog and openAlertDialog methods:

function ApproveRequest() {
var confirmStrings = { title: "Approval Request", text: "Are you sure you want to approve this request?", subtitle: "This action will approve the request", confirmButtonLabel: "Approve", cancelButtonLabel: "Cancel" };
var confirmOptions = { height: 200, width: 450 };
//New v9.0 Method
Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(successCallback, errorCallback);
}

function successCallback(success) {
//On Click on Approve Button
if (success.confirmed) {
//Here Logic to Approve the Request
//
var alertStrings = { confirmButtonLabel: "Got it..!!", text: "Request Approved Successfully" };
var alertOptions = { height: 120, width: 260 };
//New v9.0 Method
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
}
else {
var alertStrings = { confirmButtonLabel: "Got it..!!", text: "Request Cancelled" };
var alertOptions = { height: 120, width: 260 };
//New v9.0 Method
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
}
}

function errorCallback(fail) {
//On Error Logic
}

Result:

ConfirmDialog_V9_1.png

AlertDialog_V9_1

openConfirmDialog:

Here are the improvements added in V 9.0:

  1. Better UI
  2. Ability to specify labels for confirm and cancel buttons
  3. In addition to text in the dialog title and subtitle can be added
  4. Add dialog window height and width in pixels

ConfirmDialog_V9

Note: successCallback gets called for both Confirm and Cancel Buttons. Esc and x button click as well mimics Cancel Button click. Here is how we can differentiate Confirm and Cancel button the events:

function successCallback(success) {
//success.confirmed = true for Confirm Button Click
if (success.confirmed) {
//Confirm Button Click Event Handler
}
else {
//Cancel Button Click Event Handler
}

openAlertDialog:

Here are the improvements added in V 9.0:

  1. Better UI
  2. Ability to specify labels for confirm button
  3. Add dialog window height and width in pixels

When you are upgrading to Dynamics 365 v9.0, plan to rewrite code to include these new methods.

Hope it helps..!!

3 thoughts on “Dynamics 365 v9.0 – Xrm.Navigation namespace methods – Part 1

  1. Pravin Pawar

    I believe I am not wrong, but its one of the bug of Microsoft . If I want to escape from process still it select default value as second option (Cancel option), even if I when click on cross button still it select cancel option.

    Actually I want Approve and reject with escape option as well. Can you please help me to sort out this issue ?

    Reply
  2. Anonymous

    Hi,

    The openConfirmDialog() runs asynchronously. When there is a plugin on update of an entity and we use this function to show a relevant message and restrict the save of a record when clicked on ‘Cancel’ it fails as the form save has already happened due to async feature. Is there a way to run this in synchronous mode (wait till either ‘OK’ or ‘Cancel’ button has been clicked).

    Thanks.

    Reply
  3. Amar

    Hi,
    I don’t get access of primarycontrol / formcontext in call back function of confirndailog box even by passing extra parameter.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *