Dynamics 365 Business Central: How to flow/pass custom field values from Sales Order to Production Order

Dynamics 365 Business Central

Hi, Readers.
Yesterday, we discussed how to quickly create Production Orders from Sales Orders. Today, we will look at a question regarding a simple customization for this feature, how to flow/pass custom field values from Sales Order to Released Production Order. For example,
Choose the Planning action on the Sales Order page. The Sales Order Planning page shows the availability of the item.

Choose the Create Prod. Order action.

Select the status and order type.

The following table describes two ways to create production orders.

OptionDescription
Item OrderOne production order is created for each item represented by a line in the Sales Order Planning page.
Project OrderOne multiline production order is created for all items represented by lines on the Sales Order Planning page. When you use project orders, the Source Type field of the production order contains Sales Header. The order has one line for each sales line item that must be produced.

Choose the Yes button to create one or more production orders for the lines that have Prod. Order in their Replenishment System field.

Done.

What should we do if we need to pass values from the Sales Order to the Production Order? Let’s take a look at the standard code first. The primary logic for this feature has been implemented in the following codeunit.
codeunit 99000792 “Create Prod. Order from Sale”:

procedure CreateProductionOrder:

We can look for available events inside it.
For example, if it is from Header to Header, we can use the event below.
OnAfterCreateProdOrderFromSalesLine:

For Line to Line, we can use the following:
OnCreateProductionOrderOnBeforeProdOrderLineModify:

Please note that this is not the only way; it is just an available solution I found.

Next, let’s look at a simple test. I created a new field in both the Sales Header and Sales Line for testing purposes (you can also use existing fields, such as passing the Customer Name to Description 2).

Similarly, add the new fields to both the Production Order and Prod. Order Line.

Logic for Passing Values:

Test video:

Source code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL