Alert Message in Ribbon Workbench Custom Button Using JavaScript

Alert Message in Ribbon Workbench Custom Button Using JavaScript

Ribbon Workbench is widely used in Dynamics 365 to create custom command bar buttons. A common requirement is displaying an alert message when users click a custom button to provide confirmations, warnings, or informational notifications.

Using JavaScript and Ribbon Workbench together, you can easily show alert dialogs before performing actions such as record updates, validations, or integrations.

Why Use Alert Messages?

Simple JavaScript Alert

Create a JavaScript function that displays an alert message.

function showAlert()
{
    alert("Record processed successfully.");
}

Using Xrm.Navigation Alert Dialog

Microsoft recommends using Xrm.Navigation.openAlertDialog() instead of browser alerts.

function showAlertDialog()
{
    var alertStrings =
    {
        text: "Record processed successfully.",
        title: "Information"
    };

    Xrm.Navigation.openAlertDialog(
        alertStrings
    );
}

Configure Ribbon Workbench Button

After creating the JavaScript function:

  1. Create a JavaScript Web Resource.
  2. Add the function to the Web Resource.
  3. Open Ribbon Workbench.
  4. Create a Custom Button.
  5. Add a Command.
  6. Configure JavaScript Action.
  7. Select the function.
  8. Publish customizations.

Pass Selected Record Information

You can display information related to the current record.

function showRecordAlert(primaryControl)
{
    var formContext = primaryControl;

    var name =
        formContext.getAttribute("name")
                   .getValue();

    Xrm.Navigation.openAlertDialog({
        text: "Current Record: " + name,
        title: "Record Information"
    });
}
Important: Use Xrm.Navigation.openAlertDialog() for modern Dynamics 365 implementations instead of the traditional JavaScript alert() method.

Common Use Cases

Best Practices

Key Takeaways