For a while I have been experimenting with the preview version of business events in Dynamics 365 for Finance and Operations (D365F&O) and now that it has been released proper, I have set up some examples to showcase how brilliant the whole thing is.
Business events in D365F&O is relatively well documented, and you can find the documentation here.
Customer Collection Example
Now, one of my examples is this:
when the collection status of a customer transactions changes, I would like to, as a courtesy to the customer, send an e-mail informing the customer of the status and perhaps next step in the process.
Before I can set up the D365F&O side of this example, I need to create an endpoint, which subscribes to the business event. In this example I am using a Microsoft Flow as the endpoint.
The following screenshot show the Flow in its entirety.
As you can see, the Flow if triggered by a D365F&O When a Business Event occurs component. To configure the component I need to enter the D365F&O URL and then select Category and Business Event respectively using the drop-downs. Lastly, I need to select the applicable legal entity. Now this flow is ready to trigger when this specific event happens in the selected instance of D365F&O. I will explain the rest of the Flow later in this post.
If you would like the event to be processed in an enterprise context not using specific user credentials, you would need to use LogicApps instead of flow. The configuration is the same, though.
Now back to D365F&O. I go to System Administration / Setup / Business Events / Business Events to active the business event.
After selecting the applicable business event in the library, I click on the + Activate function. This allows me to select the legal entity and bind the business event to the Flow I have just created above. As you can see from my example, I have two flows available, so I need to select the right one (the other one subscribes to a sales invoice business event).
Before going back to configure the Flow, download the JSON schema for this business event by clicking on Download schema. This downloads a text file that looks like this.
Now you have configured D365F&O to send business events. All you have to do is finish the Flow Configuration.
Since I would like my flow to send an e-mail to the customer, I start by initiating a text variable that holds the mail body as shown here.
Next step is to take the content of the business event (a JSON message) and parse it. I use the Parse JSON component to do this. The schema used for this component is the one downloaded above (just paste it in).
Depending on the status of the customer transaction, I would like to compose different e-mail bodies. For this, I use the Switch component in flow.
As you can see, I can use the Status field from the JSON message I just parsed above as the variable for my switch test.
As you can see in the above screenshot, I now populate the MailBody variable by using a combination of HTML and the InvoiceId variable from the JSON message. The business event sends a limited amount of information in the JSON message, but if I need more customer or invoice information, I can always use OData to query D365F&O.
In my example I create a Case component for each customer transaction status and compose mail bodies accordingly.
Lastly, I use the Outlook 365 component to send the e-mail to the customer as shown below.
As you can see from the above, I use the MailBody variable to populate the e-mail body. I also set the Is HTML property to Yes to render the e-mail correctly.
So what happens? As the following screenshot shows, I change the status of a customer transaction from Not disputed to Disputed.
Once the status has changed, it is picked up by the system and a business event is fired to the subscribing endpoints.
As the following screenshot shows, the flow is triggered by the business event and runs successfully.
If we double-click on the Parse JSON component we can see the values passed from D365F&O as part of the business event payload.
Lastly, let’s have a look a the e-mail, the flow has generated.
Extending the Business Event Library
D365F&O comes with a substantial number of predefined business events. However, if you need other business events to support your use cases, these can easily be built by following these instructions.
In the above, relatively simple example, I have tried to show how easy it is to subscribe to a D365F&O business event and use it to automate a process beyond the boundaries of D365F&O. Obviously, this functionality can also be used to send messages to other business applications and create a loosely coupled ecosystem based on events.