Dynamics 365 – Open Confirm Dialogs | Xrm.Navigation.openConfirmDialog

Confirm dialogs are a common user interface element that seek user confirmation before proceeding with a certain action. They’re particularly useful in scenarios where an action might have irreversible consequences or requires user attention. openConfirmDialog is a valuable function for enhancing user interactions within your model driven apps. By using confirm dialogs effectively, you can provide users with clear choices and reduce the likelihood of unintended actions.

Here’s a practical code example demonstrating the usage of the Dynamics 365 Confirm Dialog:

var confirmStrings = {
text: "This is a confirmation message.",
title: "Confirmation Dialog"
};
var confirmOptions = {
height: 200,
width: 450
};
Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(
function (success) {
if (success.confirmed) {
console.log("Dialog closed using OK button.");
} else {
console.log("Dialog closed using Cancel button or X.");
}
}
);

Understanding the Parameters

confirmStrings

confirmStrings is a required parameter that contains strings to be used in the confirmation dialog. The object contains the following values:

  • cancelButtonLabel: The label for the cancel button. If unspecified, the default label is “Cancel.”
  • confirmButtonLabel: The label for the confirm button. If unspecified, the default label is “OK.”
  • subtitle: An optional subtitle to provide additional context to the user.
  • text: The main message displayed in the confirmation dialog.
  • title: An optional title for the confirmation dialog.

confirmOptions

confirmOptions is an optional parameter that contains height and width options for confirmation dialog. The object contains the following values:

  • height: An optional parameter to set the height of the dialog box in pixels.
  • width: An optional parameter to set the width of the dialog box in pixels.

successCallback

An optional function to execute when the confirmation dialog is closed. It receives an object with the confirmed attribute (Boolean) indicating whether the confirm button was clicked to close the dialog.

errorCallback

An optinal function to execute when the operation fails.

Leave a comment