Dynamics 365 Business Central: How to create Sales Order from Purchase Order with Power Automate – Copy Document from PO to SO

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to create Sales Order from Purchase Order with Power Automate (Copy Document from PO to SO).
I saw this interesting question in the Business Central Forum yesterday, more details: copy the purchase order lines to the sale order lines

As you know, Business Central has a powerful Copy Document function that can copy between different documents. For example, on the Sales Order page:

Copy document lines and header information from another sales document to this document. You can copy a posted sales invoice into a new sales invoice to quickly create a similar document.

But there is a limitation: sales can only copy sales, and correspondingly, purchases can only copy purchases. In other words, sales documents cannot copy purchase documents.

Later, I briefly tested it with Power Automate 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 action based on a flow on the Purchase 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, Copy Purchase Order to Sales Order (This will be displayed in the action bar)

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

It should be noted that since the standard Purchase Order API does not include “Customer No.” field (nor does the standard Item API), either you use a fixed Customer No. or you use your customized API. In Dynamics 365 Business Central: How to create Purchase Order from Sales Order with Power Automate (Copy lines from SO to PO), I use the same Vendor No. as the Customer No., this time I want the user to enter the customer number themselves. So choose Add an input.

The “Customer No.” field is Code data type, so here I choose the closest one, Text.

You can change the field name and instructional text.

This will be displayed when running the flow. 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 purchaseOrders API that needs to be used (Custom APIs can also be used here). Row Id is the System Id in For a selected record (V3) step.

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

PS: We can rename the step as Get Purchase Order

Then we can create the Sales Order (Sales 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 salesOrders API.

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

Customer No. takes the number entered by the user in Add an input.

My test:

Rename the step as Create Sales Order.

Next we need to find all purchase 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 purchaseOrdersLines 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 Purchase Lines.

Finally we need to create sales 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)

Select Create records (V3) action

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

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

Then select fields from Find Purchase 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.

Sales Order:

Test video:

Very simple, give it a try!!!😁

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

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

3. Of course, the reverse is also possible, such as copying from SO to PO. As long as there is an API, you can also copy the PO to Sales Quote, Sales Invoice, or Sales Return Order, etc.

4. Business Central Short: Create a Power Automate flow to copy PO to SO in less than 5 minutes

Business Central Short: Create a Power Automate flow to copy PO to SO in less than 5 minutes

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL