Skip to main content

Notifications

Dynamics 365 Community / Blogs / fajdiga.info / How to use MS Teams for Dyn...

How to use MS Teams for Dynamics 365 Business Central approval

Hi,

in this blog post, I will try to explain and show you how we can customize Dynamics 365 Business Central approval and use MS Teams for that process.

My demo will be based on Purchase Orders and the scenario is that I want to notify my procurement department that they need to approve the document (picture below).

Let’s start.

The first thing that we need to understand is that behind approval is Microsoft Power Automate flow that is sending data back and forth from Dynamics 365 Business Central.

To be able to trigger the Purchase order approval flow I need to use the trigger When a purchase document approval is requested.

In the trigger I need to specify:

  • Environment name: Production/Sandbox or any other environment for which I am configuring the trigger
  • Company name: company/ organization for which I am configuring the trigger
  • Header first condition: as I choose a business case where I am approving the Purchase Orders I need to specify the first condition on the Document Type field as we have different purchase documents stored in the Purchase Header table.
  • Header first condition is: here I will specify Order as I am creating approval workflow for the Document Type: Order
  • Header second condition: I will specify that I need to be able to send for approval only Purchase orders in defined status
  • Header second condition is: I will specify that only Open purchase orders are able to go to approval.
  • Header third condition: the third field on which I will have control is AmountIncludingVAT this means that when sending for approval document, the flow will first check this field and if the value in AmountIncludingVAT is valid for value.
  • Header third condition is: I will specify what should be a condition for AmountIncludingVAT. I specify >0 and that means that every Purchase order that has an amount including VAT greater than 0 should go for approval. Here I can specify for example > 1000 and in that case, only a Purchase order with an amount including VAT greater than 1000 will go to approval.

Now when I have the condition on which flow will be triggered I can specify actions. The first action that I need to specify, is to get the record that is sent for approval from Dynamics 365 Business Central.

In the Get record action I need to specify:

  • Environment name: Production/Sandbox or any other environment for which I am configuring the action
  • Company name: company/organization for which I am configuring the action
  • Table name: table in which my workflow requests are registered. As I am creating an approval workflow for Purchase orders, I have to use workflowPurchaseDocuments.
  • RowId: I will pass value from trigger to get exactly the Purchase order for which I triggered the approval workflow.

Now when I have all the needed data from Dynamics 365 Business Central in my flow I can start posting the message to MS Teams. As, I want to create custom card with custom actions I chose Adaptive Card for the approval process.

In the action Post an Adaptive Card to a Teams channel and wait for a response I need to specify:

  • Team: Team in which I will post the message
  • Channel: Channel in which I will post the message
  • Message: in the message, I will specify all the code that will be executing when I will post the approval request in the Teams channel.

In my first TextBlock I specified my title of the adaptive card. The title will also include a number of the purchase order. The number I will get from the Get record action.

My second TextBlock contains detail information about the purchase order such as Number, Vendor Name, and Amount Including VAT.  All data is from Get Record action.

My third part of the adaptive card is the Action block of code where I specified all the buttons that the user will see.

I have 3 buttons:

  • Approve: it will give me the Approved output from the action
  • Reject: it will give me the Rejected output from the action
  • View document: it will navigate the user from MS Teams to the Dynamics 365 Business Central and open the specific purchase order. In the URL I specified filters to open the Purchase order card (&page=50) filtered by Document Type from the Get record action (&filter=Document Type is ‘Document Type’) and purchase order number from Get record action (AND ‘No.’ IS ‘No.’). Make sure that you put values in the apostrophes. 

At the end of the action, I specified the message that will be shown after the user select Approve or Reject.

In my next action, I need to store the output from the adaptive card based on user selection. For that purpose, I will use the action Initialize variable

In the checkStatus variable, I will store the output from the actions in Post an Adaptive card action. To be able to catch this parameter first I must test few times to see what is the output of the adaptive card.  In the picture below I see that status is Rejected because I click on the Reject button

Now all I need is to check the status of the variable and execute different actions in Dynamics 365 Business Central.  So next step is a condition where I check if variable value is Approved

If the condition is true the flow will go to the Yes branch.

In the Yes branch I will specify:

  • Environment name: Production/Sandbox or any other environment for which I am configuring the action
  • Company name: company/organization for which I am configuring the action
  • Action name: action that I want to execute by the flow. In my case, if the value of variable checkStatus is Approved this means that the user approved the purchase order and I can approve it in the Dynamics 365 Business Central. For example, in other cases, you can choose to post the documents, convert quote to order, etc.
  • WorkflowStepInstanceId: I need to specify what is my workflow instance id. This I will get in trigger When a purchase document approval is requested.

If the condition is false the flow will go to the Nobranch.

In the No branch I will specify:

  • Environment name: Production/Sandbox or any other environment for which I am configuring the action
  • Company name: company/organization for which I am configuring the action
  • Action name: action that I want to execute by the flow. In my case, if the value of variable checkStatus is not Approved this means that the user rejected the purchase order and I can reject (reopen) it in the Dynamics 365 Business Central.
  • WorkflowStepInstanceId: I need to specify what is my workflow instance id. This I will get in trigger When a purchase document approval is requested.

And that’s it, our first approval of Dynamics 365 Business Central purchase order from the MS Teams is ready.

Additionally, I would like to point to the web site https://adaptivecards.io/designer/ where you can always test your code for the adaptive cards.

That is all for this blog post.

Br,

Renato

The post How to use MS Teams for Dynamics 365 Business Central approval appeared first on fajdiga.info.


This was originally posted here.

Comments

*This post is locked for comments