Dynamics 365 Business Central: How to create Purchase Order from Sales Order with Power Automate (Copy lines from SO to PO)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to create Purchase Order from Sales Order with Power Automate (Copy lines from SO to PO).
I saw this interesting question in the Business Central Forum yesterday, more details: Power automate to copy lines from Sales order to Purchase order? (dynamics.com)
Later, I briefly tested it and found that it was not very difficult, so I would like to share it in this post, hoping to help more people.

Power Automate is a service that helps you create automated workflows (or flows) between apps and services, like Business Central. With Business Central, you’re given a license to Microsoft Power Automate. This license lets you use your Business Central data as part of a workflow in Microsoft Power Automate. You create flows and connect to your data from internal and external sources through the Business Central connector.

Let’s start.
Choose Power Automate -> Create automated flow on the Sales Order page

Then choose Create a flow. (Because there is no template for this requirement)

The page will jump to the Power Automate design page.

PS: Disable New designer in the upper right corner to return to the previous designer.

In this post, I shared it on the previous designer and the new one is the same.

First, give the flow a name.
For example, Create Purchase Order From Sales Order (This will be displayed in the action bar)

Search for Business Central, and click on it.

Then select For a selected record (V3) trigger

Select the environment and page or table that needs to be connected. More details: “For a selected record (V3)” trigger in Power Automate

Click New step. Search for Business Central, and click on it.

Select Get the record (V3) action

Select the BC environment that needs to be connected and the salesOrders API that needs to be used (Custom APIs can also be used here). Row Id is the System Id in Seleted Sales Order.

At this time you can save the flow and simply test whether you can get the sales order.

PS: We can rename the step as Get Sales Order

Then we can create the Purchase Order (Purchase Header) first. Click New step. Search for Business Central, and click on it.

Select Create record (V3) action

Select the BC environment info and standard purchaseOrders API.

Then we can map some fields to the Purchase Order from Sales Order.

It should be noted here that since the standard Sales Order API does not include Vendor No. (nor does the Item API), either you use a fixed Vendor No. or you use your customized API. I am using a standard database, so I use the same Vendor No. as the Customer No.

Or, you can add additional input parameters to let user enter a vendor no.

Rename the step as Create Purchase Order.

Next we need to find all sales order lines. Click New step. Search for Business Central, and click on it.

Select Find records (V3) action

Select the BC environment info and standard salesOrdersLines API.

Then click Show advanced options.

Enter filter query. “$filter” is already included in parameters, so there is no need to add it manually. More details: filter in API
For example,

More details: How to do “if Record.Find then” in Power Automate (Check if the record already exists or not)

Rename the step as Find Sales Lines.

Finally we need to create purchase order lines. Click New step. Search for Business Central, and click on it. (Note that there is no need to manually add the Apply to each action here)

Just like the steps to create a Purchase Order, first select the environment information, and then select the standard purchaseOrderLines API.

Then map the field’s value. Document Id is the Id of the Create Purchase Order step.

Then select fields from Find Sales Lines step. After adding any field, Apply to each action will be automatically added.

Then continue to set the required fields.

Save the flow and you’re done.

Test:

Great.

Test video:

Very simple, give it a try!!!😁

Download My Test flow:

PS:
1. If you need to run the flow automatically, you can use the trigger below. (Please note that you need to get the sales order first. You can also find all sales orders and create them into purchase orders)

2. This time I mainly used standard APIs, you can also use custom APIs

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL