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?
- Notify users before executing actions
- Display important warnings
- Provide confirmation messages
- Improve user experience
- Reduce accidental actions
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:
- Create a JavaScript Web Resource.
- Add the function to the Web Resource.
- Open Ribbon Workbench.
- Create a Custom Button.
- Add a Command.
- Configure JavaScript Action.
- Select the function.
- 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
- Record validation messages
- Confirmation notifications
- Process completion alerts
- Warning messages
- Custom workflow execution
- Integration status updates
Best Practices
- Use meaningful alert titles.
- Keep messages concise.
- Use modern Xrm.Navigation APIs.
- Avoid excessive popup messages.
- Test ribbon commands across environments.
Key Takeaways
- Ribbon Workbench custom buttons can execute JavaScript functions.
- Alert dialogs improve user interaction.
- Xrm.Navigation.openAlertDialog() is the recommended approach.
- Messages can display record-specific information.
- Useful for validations, confirmations, and notifications.