4

In the CRM solution I am working on, there is a case where the user needs to be shown a warning message based on plugin execution results after submitting a particular form. The operation should still complete successfully, so throwing an exception from the plugin is not a good solution.

From searching around, there does not seem to be a straight-forward way to do this.

Is the only option to save the warning message contents to a custom field on some entity and use a javascript function on the form to determine when to display it to the user?

K. Oja
  • 83
  • 7

3 Answers3

3
  1. Implement a Custom Workflow Activity with the business logic your plugin is currently doing.

  2. Create and activate an action that uses that Workflow Activity.

  3. Code a JS function associated to the form's OnSave event that calls this action by doing a WebApi request. Lastly, after the action is processed you can call the out of the box setFormNotification Client API to create a custom warning message at the top of the form.

You will end up with a nice custom message like this:

enter image description here

André Cavaca
  • 510
  • 1
  • 5
  • 18
  • 1
    Thank you for the reply. I am not sure if it will be practical to utilize this for us, since it would require reworking a lot of established logic just to handle a minor edge case. I think we might just try to find a different approach to meet the user's requirements without having to rely on this form returning a warning message. Perhaps it will be useful to someone else though. – K. Oja Mar 19 '19 at 21:47
  • Instead of showing a notification (setFormNotification) you could use a [confirm dialog](https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-navigation/openconfirmdialog) and [stop or continue the saving of the record](https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/save-event-arguments/preventdefault) according to the clicked button – Marcelo Acosta Mar 21 '19 at 01:08
1

Yes there’s no straight forward way.

You can have a dummy field on the same entity record, set/update that field value from plugin per your warning message need & onChange of that field will be triggered in UI on successful plugin execution.

You can display the message to user from that onChange handler. Read more

Documentation says:

Field OnChange event

This event also occurs when data changes on the server are retrieved to update a field when the form is refreshed, such as after a record is saved.

This way you can have a successful plugin execution without throwing InvalidPluginExecutionException, can avoid custom entity, custom Action, etc

1

Well you could use Actions.

Create action with output Parameter. Register your plugin in the Custom Message(Action). Call the Action using JavaScript on Save event of the form. You will receive Output from action in JavaScript, same can be shown in the form.

We know we can show Notification using JavaScript, and we are Calling action which will execute the Plugin registered to the Custom Message and You will get the Output in Javascript variable that you can show using Javascript only.

Refer this link to work with Actions. https://www.magnetismsolutions.com/blog/dominicjarvis/2017/09/18/how-to-trigger-plugins-on-custom-messages-using-actions-in-dynamics-365

Nachiket
  • 620
  • 6
  • 23