In Dynamics 365, plugins run server-side, so they don't have direct access to the user interface to display messages. However, you can achieve this functionality using one of the following approaches:
1. Use a Custom Action and Synchronous Workflow/Plugin
Create a custom action that triggers your plugin logic.
Call this action from a JavaScript web resource or through Power Automate.
Return the success or failure message as part of the action's response.
Display the message to the user using JavaScript on the form or a dialog.
Steps:
1. Create a custom action in the Dynamics solution.
2. Register the plugin on the custom action's execution.
3. Use JavaScript to call the action and handle the response.
4. Show error message using openAlerDialog api.
2. Throw Exceptions in Plugin
If the plugin fails, you can throw an exception with a user-friendly error message. Dynamics will display the error to the user.
For successful operations, this method doesn't work, as no "success message" mechanism exists for plugins.
Example:
if (operationFailed)
{
throw new InvalidPluginExecutionException("Document creation failed due to invalid data.");
}
3. Use a Real-Time Workflow/Flow to Update a Field
Update a custom field (e.g., "Status Message") on the record with the success or failure message after the plugin completes.
Add a notification or JavaScript logic to display the message when the field is updated.
Steps:
1. Create a custom text field on the entity (e.g., statusmessage).
2. Update the field from your plugin with the desired message.
3. Use form scripting to display the field's value as a notification.
var statusMessage = formContext.getAttribute("statusmessage").getValue();
if (statusMessage) {
Xrm.Navigation.openAlertDialog({ text: statusMessage });
}
4. Create a InApp Notification.
You can create a InApp Notification from plugin it self. So no need of Any Client side code.
Which Approach to Choose?
Simple error messages: Throw exceptions in the plugin.
Interactive success and error messages: Use Custom Actions or Custom APIs with JavaScript.
Record-level feedback: Update a field with the message and display it using form scripting.