How to Trigger Plugins on Custom Messages using Actions in Dynamics 365

Dominic Jarvis, 18 September 2017

When modifying a Microsoft Dynamics 365 solution, you may require functionality that is portable and can be triggered in multiple circumstances. For example, running a rollup field calculation job, which is able to be done from SDK messages, but otherwise cannot be triggered manually out-of-the-box. In this instance, you may require a plugin or a custom workflow activity that calls the SDK message and runs the job. However, if you want to be able to run this from multiple places, a plugin may be more appropriate.

How does this work?

Custom actions were added in Microsoft Dynamics CRM 2013, and provide a fantastic point against which to register plugins. Once actions have been created, it is possible to register a plugin against their schema name, which acts like a custom SDK message that is fired whenever the action is called.
Custom actions can provide the target for a plugin as well as pass values to plugins. This is done by setting input parameters for the custom action and then accessing these using from the plugin execution context.

To register a Plugin against a Custom Action:

  1. Navigate to your Solution > Processes > New
  2. Enter a Process name and select Action as the Category. For the Entity, select the entity for which you want to fire the Plugin. Note that the Process name that you enter will be what you use to refer to the action later when you register the plugin, so pick a name that will make it easy to identify.
  3. Click OK, add any additional steps and functionality you want to the action, then add any input parameters that you need for either your internal steps or for your plugin.
  4. Create your plugin.
  5. Register your plugin using the plugin registration tool bundled with the SDK.
  6. Right click on your plugin in the tool, and select ‘Register New Step’.
  7. In the Message field, select the custom action you previously created.
  8. Finish registering step as normal.
  9. Add action to wherever you want the plugin to run.


Why is this useful?

Custom actions allow for a useful target for plugins to fire in multiple circumstances. For example, while a workflow activity could perform the same functionality, a custom workflow activity can only be called from a workflow or a process, while a custom action can be called from JavaScript and is generally more flexible, as the action itself can be edited and have functionality added inside CRM.