Power Automate Create Sales Order from Purchase Order

Recently, I've been playing around with the improvement of Power Automate within Business Central, So I've tested with a scenario below: 

Scenarios: Create Sales Order from Purchase Order 

I begin by selecting Create action based on a Flow from Purchase Order page. This opens a pop-up page Create a flow, where I select Create from blank



This will take you to PowerAutomate designer page, there is a new New Designer option which is turned on by default. I prefer to work with the old style so I turned it off (you might like the new style)


Give your PowerAutomate a name i.e. Create SO from PO, then select the environment and page or table to connect to


After filled in the info, we need to add input. In this case, I want a Customer Number, which will be used to create the Sales Order.



This will appear on the Purchase Order page when this flow is running.




Click New Step, then choose Dynamics Business Central and select Get Record (V3)
Fill in the info of the env and the API to connect to, in this case is PurchaseOrder API. In the Row ID choose System ID field.


Rename this step as "Get Purchase Order" to make it more easily readable.


Next step after getting the Purchase Order record, we want to use this to create Sales Order header record. Similar to the previous step, click on New Step then choose Dynamics Business Central and this time select Create record(V3) action
Fill in the info that are required in order to create Sales Order as per below as an example



Note: Customer No. is the input from the user that we have added in the very first step above
Next we need to get all the purchase lines. Click on New Step then choose Dynamics Business Central and this time select Find record(V3) action
Fill in the info as per below and click on Show advanced options to expand it
Enter filter query to be filter only on the Purchase lines that are linked to the Purchase heard record in the previous step Get Purchase Order

Note: Ensure that selected Id is from Get Purchase Order


After getting these Purchase lines, the last step is to create Sales order lines. Click on New Step one more time then choose Dynamics Business Central and this time select Create record(V3) action

Fill in all the info as per previous step, the only different here is the Table name

Now map the Document Id of Sales Line record to the Sales Header Id


The next step is to map other fields from Purchase Line to Sales Line, please note that after adding a field, Apply to each action will be added automatically.

That's it! now save the flow.

Test:

Go to Purchase order page in Dynamics BC, select a Purchase order. Click on Power Automate, you will see your new Flow action button

Enter the Customer number then click on Run flow


Voila! Sales order is created
Now if we go back to the Flow itself, we can see the run history




That’s it! Give it a try yourself and share your thoughts on other scenarios where Power Automate could be a better choice than customizing Business Central with AL.




Comments

Popular Posts