Skip to content

Dynamics 365 – Trigger a plugin from a Business Process Flow

Introduction

Here at Sigao, we’ve been working with the Microsoft’s Dynamics platform for quite some time. We’ve often had situations where we have some custom action that we want to use to activate one of our custom plugins. Here, I’ll walk you through how to trigger one of your plugins automatically as a user progresses through a business process flow. The overall flow of this process is described below.

Execution flow

First, a business process flow event will execute a custom workflow. That workflow will in-turn trigger the execution of a custom action. Lastly, we will register our plugin step against the custom action message, so that when the action occurs, our plugin executes.

Step 1 – Create action

Our first step is to create a custom action. Dynamics 365 allows us to register our plugin steps against these custom actions, so we’ll use one to trigger our plugin. Actions are created in the “Processes” list in the customizations. You can learn more about actions and other processes here. For our example, we’ll set the context of our action to the “Account” entity.

Dynamics 365 Create new action

After saving your custom action, make sure to click the “Activate” button.

Step 2 – Create workflow

Next, we’ll create our workflow that will trigger the action we just created. Again, you can create new workflows in the “Processes” list. Make sure you set the Entity field to “Account,” and create your new workflow.

Dynamics 365 Create new workflow

After creating your workflow, you’ll be presented with a screen that provides you with an array of options. First, you’ll want to select “As an on-demand process.” This will allow us to trigger our workflow from our business process flow. Second, you’ll want to deselect “Record is created.” We only want our workflow to fire when the business process flow tells it to, not when the account is created.

Dynamics 365 Edit workflow settings

After changing the above settings, you’ll want to add a new step to the workflow. If you’d like, you can add multiple steps, or even some branching logic, but for our example we’ll simply trigger the custom action. Add a step of type “Perform Action,” then select our custom action and the account entity.

Dynamics 365 Add workflow step

Next, you’ll want to click on the “Set Properties” button, which will bring up the screen below. Go ahead and add “Account” as the value for the “Target” property. This essentially tells the workflow to pass the account it is currently operating on to the action, so that the action knows what account to execute against.

Dynamics 365 set action target

Once you’ve clicked “OK,” make sure to save your workflow, and activate it by clicking the “Activate” button.

Step 3 – Create Business Process Flow

Again, head on over to “Processes” to create your new business process flow. As before, make sure to set the entity to “Account” and the category to “Business Process Flow.”

Dynamics 365 Create business process flow

 

We won’t dive very deep into how to create business process flows, but if you would like to learn more, you can do so here. Below, you can see a simple 3 stage business process flow we’ve created.

 

Dynamics 365 simple business process flow designer

As you can see below, you can specify one or more workflows within a business process flow stage. The designer allows you to have these workflows execute on entrance or exit of a business process flow stage. However, we aren’t going to do that in this demo.

Dynamics 365 business process flow stage

In our demo, we’re going to have the workflow executed once the business process flow completes. To do this, we’ll simply drag a new workflow component into the “Global Workflow” area. Dynamics 365 Business Process Flow workflow

Once the workflow has been added, we’ll update the workflow’s properties. Make sure to select the correct trigger, in our case “Process completed,” and select our workflow. Once that is done, make sure you hit “Apply” or your changes will not be saved. Then, save the business process flow, and make sure to activate it.

Dynamics 365 Business Process Flow workflow properties

Step 4 – Register your plugin

Next up: register our plugin against our custom action. Using the plugin registration tool, we’ll simply register a new step, with our action as the message. In this case, we don’t need to set a primary or secondary entity.

Dynamics 365 register plugin custom action

Step 5 – Execute your business process flow

Now all we have left to do is test our work. Simply go to an account record and step through and finish our business process flow. Once we’ve done that we’ll head on over to the plugin trace log to see the results.

Dynamics 365 Business process flow Dynamics 365 plugin trace log

All our demo plugin does is trace the account id corresponding to our business process flow, which we can see in the trace log below.

Dynamics 365 plugin trace log

It didn’t work!

If you ran into problems during this walkthrough, I’d try the following:

  • Make sure your changes have been published
  • Make sure your action, workflow, and business process flow have been activated
  • Restart the plugin registration tool (sometimes custom actions won’t show up until you restart)
  • Make sure that you clicked “Apply” on your business process flow stage, step and workflow properties

Please let us know if you have any questions or suggestions regarding this post, as we’d love to hear feedback, as well as discover new ways to solve problems in Microsoft Dynamics 365.