web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

Extend Dynamics 365 Finance and Operations Workflows with Business Events

Henrik Larsen Profile Picture Henrik Larsen 646

Back when Business Events were introduced in Dynamics 365 Finance and Operations (D365F&O), a slightly overlooked use case was the ability to extend inbuilt workflows to external endpoints such as Power Automate.

In this blog post I explore how to use a Business Event to execute the approval process in Power Automate for a general ledger journal.

Designing the Inbuilt Workflow

To kick things off, I create a simple general ledger journal approval workflow using the inbuilt designer as shown below.

General ledger journal approval workflow

As you can see, the workflow is quite simple in this example and only contains a single approval activity. Once I save the workflow, Business Events representing the workflow elements are automatically created in the catalogue:

Workflow elements in the Business Events catalogue

Connecting the Business Event to Power Automate

Since we are going to make the actual approval happen in Power Automate, the Business Event we are interested in is in the category called “Workflow workitem” as this is the category used for the actual work items in the workflow.

To connect the business event to Power Automate, we need to set up an endpoint in the Business Event catalogue. Before you can set up an endpoint, you need to create the Power Automate flow that the endpoint will point to.

As shown below, I create a new flow with the “When a Business Event occurs” trigger on the D365F&O connector.

Power Automate flow trigger

Once the flow has been saved, you can use the flow URL to set up the Business Event endpoint.

When the endpoint has been created, you can activate the business event.

Power Automate Approval

Now the Business Event is linked to the Power Automate flow, and we need to design the actual flow to replace the inbuilt approval process.

Parse Business Event payload JSON

After the trigger, the first step in the flow is to parse the JSON supplied as a payload with the Business Event. This allows us to reference workflow data later in our flow.

Capture workflow instance ID as a string

Next we want to capture the workflow instance in a string variable to allow us to query and update the workflow item later in the flow.

Check the state of the workflow

Before we send the workflow item for approval with the user, we need to ensure that it is in a state that allows for approval. In this case we are using the “Execute action” action on the D365F&O connector in Power Automate calling an action named “WorkflowWorkflowItems-validate” with the workflow instance as a parameter.

Acting on workflow state

If the response from the check is “True”, the workflow is in a ready-state for approval actions to be applied.

Configuration of the approval action in Power Automate

In Power Automate I use the Approval action to start the approval process. In this example I use data captured in the payload (see above) to fill in the Approval action properties.

Firstly I use the “WorkflowUserEmail” value to assign the approval request to the user assigned to the workflow item.

Subsequently, I fill in the details of the message with “WorkItemOwner” (user) and “WorkflowStepInstruction” (instructions from the workflow item).

Lastly, I use the “LinkToWeb” value for the Item link property. This allows the user to click on the link in the approval request and jump straight to the ledger journal in D365F&O.

Once the user has approved or rejected the approval request, we need to update the workflow item with the result.

Update workflow item with approval result

As you can see from the above, I am using the “WorkflowWorkflowItems-complete” action for this. I am using the “Outcome” property from the Approval action to set the outcome in the workflow item.

The possible outcomes for the workflow item are available in the payload and can be used in the approval request.

I am using the “Response summary” from the approval request in the Comment field and the “WorkItemOwner” from the payload as the RunAsUser.

Testing

So now it is time to test our configuration. To get started I create a new general ledger journal and select Submit from the ribbon:

Submit general ledger journal for approval

Assuming that everything is configured correctly, the user now receives an approval request. In my case I am using the Approvals app in Teams (who would have guessed?).

This screenshot shows the approval I receive in Teams:

Teams approval request

The same request is also sent by e-mail to the user.

From the request I can approve or reject the item, but I can also click on the link to jump directly to the general ledger journal.

When looking at the workflow history from the general ledger journal in D365F&O, we can now see that the workflow item has been approved:

Workflow item history

As I have showed in this blog post, we can extend inbuilt workflows using Business Events and, in this case, Power Automate. Beyond external approval, this opens up a range of options for external data processing as part of a workflow.


This was originally posted here.

Comments

*This post is locked for comments