Purchase Order Approvals in D365FO with Power Automate
Ahmed Ali EL-Bardisy
Senior ERP consultant with in-depth knowledge of Dynamics 365 and a strong ability to drive transformative change, optimize business processes, and deliver value-added solutions to clients.
In today's digital era, businesses are constantly seeking ways to automate and streamline their processes. Dynamics 365 for Finance and Operations (D365FO) offers a powerful platform for managing various aspects of operations, including purchase orders.
With the integration of Power Automate, a cloud-based workflow automation tool, organizations can further enhance their efficiency by automating the approval of D365FO purchase orders. In this article, we will explore the interesting concept of leveraging Power Automate to streamline purchase order approvals in D365FO. Before we delve into the details, let's address an essential prerequisite:
Ensuring the user company "in user options" matches the company used for creating the flow.
According to the lengthy flow that cannot be displayed in one page, I will attempt to share it in five segments and describe it sequentially.
Segment 1:
The flow begins with the initial trigger, which could be a specific event, which is purchase order submittion through D365FO. Once triggered, the flow moves on to the first set of actions, where certain conditions are checked or data is retrieved from a source.
Segment 1: Step 1 - Triggering the Approval Workflow with a Business Event
In this segment, we will focus on the initial step of triggering the approval workflow using a specific business event.
Segment 1: Step 2 - Obtaining the Schema of the Business Event
We will focus on parsing the downloaded JSON schema in Power Automate using the "Parse JSON" action. The Parse JSON action is a powerful tool that allows you to extract specific values from the JSON data and use them as dynamic content within your flow. Follow the steps below to accomplish this:
Segment 1: Step 3 - Adding a Validation Action for Flow Testing
In this segment, we will focus on adding a validation action to your flow. Although this step is not mandatory, it can be helpful as a breakpoint or check to verify if your flow is functioning correctly and retrieving data accurately.
Segment 1: Step 4 - Adding a Compose Action with Split Function
In this segment, we will focus on adding a Compose action to the flow and using the Split function within it. The Compose action is a data operation in Power Automate that can be used to manipulate and transform data. We will use the Split function to extract the Purchase Order (PO) number from the "workflowDocument" variable. Follow the example below for the expected output:
Segment 1: Step 5 - Getting the PO Record using the "Get Record" Action
In this segment, we will focus on using the "Get Record" action to retrieve all the details related to the Purchase Order (PO) record using the output from the previous step, which is the extracted "PO number". Follow the steps below to accomplish this:
Segment 2:
Segment 2- step 6: List all purchase order lines.
We will list all lines related to a specific purchase order to be printed in an email. You can achieve this by filtering the lines using a filter query with the condition "purchaseOrderNumber eq [purchase order number]". Here's an example of how you can implement this step:
After extracting the purchase order number from the previous compose step, you can use it in the filter query "outputs('Compose')"
Segment 2- step 7: you need to use the Data Operation - Select action to transform the shape of objects in an array and select specific variables from the purchase order lines to be printed later in the email body. Here's an example of how you can implement this step:
Segment 2, step 8, I've used the "Parse JSON" action again to parse the JSON data and separate each variable individually. This step is necessary because if you try to access the data directly from the "Select" step, it would pass as a single variable instead of being segregated for each object.
Using the "Parse JSON" action allows you to extract each individual variable from the JSON data and use them separately in subsequent steps. Here's an example of how you can implement this step:
Segment 2- Step 9: we initialize a new variable called "Approval Message" in order to store data "Po Lines"for later use. The variable is of type string and has a value consisting of two parts: a fixed value, which represents the table header of the message, and a variable value, which corresponds to the PO lines. To emphasize the text and align the values, we utilize the markdown language. For example, we use double asterisks (**) to make the text bold and colons (:) for alignment. If you want to learn more about markdown language, you can refer to the following link: Getting Started | Markdown Guide .
Segment 2- Step 10, we initialize another variable called "PO SUM." This variable is used to store the total amount of the purchase order (PO). Since the total amount is not readily available as a field in the Purchase Order data entity, we need to calculate it by summing up the amounts of all the PO lines. The variable "PO SUM" is of type float, which allows it to store numbers with decimals, and we initialize it with a value of zero. This variable will be used to accumulate the amounts of the PO lines and represent the overall PO amount.
领英推荐
Segment 3
We will perform our calculations and store the data in the variables we created in the previous steps.
Segment 3 - Step 11: we will store the values of the PO lines in a variable called "Approval message." To accomplish this, we will utilize the "Apply to each" action. The "Apply to each" loop allows us to iterate through a list or data table and process each item individually. In this case, the list represents the PO lines.
Within the loop, we will retrieve the values of each PO line, including the item number, category, quantity, unit price, and line amount. These values will be concatenated and formatted to create the content of the "Approval message" variable.
The "Apply to each" loop ensures that we perform the necessary actions for each PO line, allowing us to gather all the relevant information and construct the complete "Approval message" variable. This approach enables us to handle multiple PO lines efficiently and utilize their data in subsequent steps of the process.
Here, i selected the "Body of Parse JSON-1" action for looping.
Inside the "Apply to each" action, we have inserted another action called "Append to string." This action allows us to add or join additional text to an existing string. In other words, it allows us to concatenate multiple pieces of text into a single long text string. This process of combining strings is commonly referred to as string concatenation.
In Power Automate, we use the "Append to string variable" action to achieve this functionality. When configuring this action, you need to select a variable of type "String" in the "Name" field. This variable will store the concatenated string values. In the "Value" field, you pass the values of the objects that were extracted from the "Parse JSON" action in the previous steps. These values will be appended to the existing string stored in the selected variable.
By utilizing the "Append to string" action in the "Apply to each" loop, we can gradually build and update the "Approval message" variable with the extracted values from each iteration. This allows us to dynamically construct the final string by combining all the relevant data from the PO lines.
Segment 3 - Step 12, we will store the line amount of each PO line in a variable called "PO SUM." To achieve this, we will continue utilizing the "Apply to each" action, which allows us to iterate through the list or data table representing the PO lines and process each item individually.
Within the loop, we will select the "Body/Value" from the step "list items Present in table." the function will loop over all rows of selected table.
Inside the "Apply to each" action, we have inserted another action called "Increment Variable ."To increase or increment a variable by a constant value, add the Increment variable action to your flow. This action works only with integer and float variables.
You need to select a variable of type "Float /Integer" in the "Name" field. This variable will store the accumulated values. In the "Value" field, you pass the value of the line amount total as attached picture.
Here, the action will loop for each line in purchae order lines table then add this amount to "PO amount" variable.
Segment 3 - Step 13, we will add the action called "Start and wait for an approval." This action allows us to obtain approvals from users without requiring them to log in to D365 Finance and Operations. The action provides a user-friendly approval interface and captures the decision made by the approver.
When configuring the "Start and wait for an approval" action, we need to specify the following parameters:
By incorporating the "Start and wait for an approval" action with the specified parameters and dynamic values, we enable the approval process to proceed smoothly and efficiently, allowing users to provide their approvals without logging in to D365 Finance and Operations.
Segment 4
We will check the outcome of the approval step and based on that, respond to the original workflow in D365 Finance and Operations.
Segment 4- Step 14: Conditional Logic
Using conditional logic, we will evaluate the approval outcome. If the request was approved, we will proceed with the appropriate actions in the workflow. On the other hand, if the request was rejected, we will handle the rejection accordingly.
Segment 4- Step 16: Response to D365 FO Workflow
In this step, we will respond to the original workflow in D365 Finance and Operations based on the approval outcome. If the request was approved, we will trigger the subsequent actions in the workflow, such as updating the status of the purchase order or initiating further processes.
If the request was rejected, we will handle the rejection by notifying relevant parties, updating the workflow status, or taking any necessary corrective actions.
In both the true and false paths of condition, where we handle the outcome of the approval step, we can add an "Apply to each" action. This action allows us to iterate through a list or data table and perform actions on each item individually.
In this case, we will select the response of the approval step as the input for the "Apply to each" action. This means that we will iterate through each response received from the approval step, whether it is in the true path (approval granted) or the false path (approval rejected).
Inside the "Apply to each" action in segment 4, we will add another action called "Execute action" in Finance and Operations. This action allows us to trigger specific actions or processes within the D365 Finance and Operations system based on the outcome of the approval step.
When configuring the "Execute action" action, you will specify the details of the action or process that needs to be executed. This could include actions such as updating the status of the purchase order, creating a new record, initiating a workflow, or any other supported action within the Finance and Operations system.
By placing the "Execute action" action within the "Apply to each" loop, we ensure that the action is performed for each response received from the approval step. This allows us to individually execute the necessary actions based on the outcome of each approval decision.
The action mentioned is "WorkflowWorkItems-complete" within the Finance and Operations system. To configure this action, follow these steps:
WorkflowWorkItemInstanceId: Select the value of the "Parse JSON" action that contains the Workflow Instance ID. This will populate the WorkflowWorkItemInstanceId field with the appropriate value.
Outcome Field: Select the outcome from the approval step as the value for the Outcome field in the WorkflowWorkItems-complete action. This will indicate whether the approval was approved or rejected.
Comment: Select the comment from the approval step as the value for the Comment field in the WorkflowWorkItems-complete action. This allows you to include any comments or additional information associated with the approval decision.
Run As User: Select the responder email from the approval step as the value for the Run As User field in the WorkflowWorkItems-complete action. This ensures that the action is executed on behalf of the appropriate user who responded to the approval request.
By configuring the WorkflowWorkItems-complete action with the Workflow Instance ID, outcome, comment, and the user who responded to the approval request, you can complete the specific workflow item within the D365 Finance and Operations system. This action helps to update the workflow status and progress based on the approval decision made by the user.
In conclusion, it's important to note that the functions and workflows discussed in this guide are highly configurable. When I first started exploring these concepts, I came across various articles and resources that presented alternative, easier approaches to achieving similar outcomes. This highlights the fact that there is no fixed or rigid way of implementing workflows . Each individual or organization can adapt and customize these functions according to their specific needs and preferences. The flexibility of the platform allows users to tailor workflows to their unique requirements and adopt their own approaches. So, feel free to explore different resources, experiment with different techniques, and find the methods that work best for you. Thank you for reading!"
MCP - MS Dynamics 365, Power Apps, Power Automate
3 个月Ahmed Ali EL-Bardisy, many thanks for sharing such a useful post.
Founder & CEO, Group 8 Security Solutions Inc. DBA Machine Learning Intelligence
8 个月Your post is valued, thanks!
MD365 Application Consultant SCM & production control At PROART Consulting _Certified D365 SCM Functional Consultant Associate
8 个月good job????
Impressive insights on leveraging Power Automate to enhance efficiency in purchase order approvals – automation is indeed key in modern business operations!