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..!!

Leave a Reply

Your email address will not be published.