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.
| Option | Description |
|---|---|
| Item Order | One production order is created for each item represented by a line in the Sales Order Planning page. |
| Project Order | One 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)
codeunit 50112 EventHandlers
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Create Prod. Order from Sale", OnAfterCreateProdOrderFromSalesLine, '', false, false)]
local procedure PassValuesFromSalesHeaderToProductionOrder(var ProdOrder: Record "Production Order"; var SalesLine: Record "Sales Line")
var
SalesHeader: Record "Sales Header";
begin
if SalesHeader.Get(SalesHeader."Document Type"::Order, SalesLine."Document No.") then
ProdOrder."ZY Test Field" := SalesHeader."ZY Test Field";
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Create Prod. Order from Sale", OnCreateProductionOrderOnBeforeProdOrderLineModify, '', false, false)]
local procedure PassValuesFromSalesLineToProdOrderLine(var ProdOrderLine: Record "Prod. Order Line"; var SalesLine: Record "Sales Line")
begin
ProdOrderLine."ZY Test Field" := SalesLine."ZY Test Field";
end;
}
tableextension 50113 SalesHeaderExt extends "Sales Header"
{
fields
{
field(50100; "ZY Test Field"; Text[100])
{
Caption = 'ZY Test Field';
DataClassification = CustomerContent;
}
}
}
pageextension 50113 SalesOrderExt extends "Sales Order"
{
layout
{
addafter("Sell-to Customer Name")
{
field("ZY Test Field"; Rec."ZY Test Field")
{
ApplicationArea = All;
Caption = 'ZY Test Field';
ToolTip = 'This is a test field for demonstration purposes.';
}
}
}
}
tableextension 50114 SalesLineExt extends "Sales Line"
{
fields
{
field(50100; "ZY Test Field"; Text[100])
{
Caption = 'ZY Test Field';
DataClassification = CustomerContent;
}
}
}
pageextension 50114 SalesOrderSubformExt extends "Sales Order Subform"
{
layout
{
addafter("No.")
{
field("ZY Test Field"; Rec."ZY Test Field")
{
ApplicationArea = All;
Caption = 'ZY Test Field';
ToolTip = 'This is a test field for demonstration purposes.';
}
}
}
}
tableextension 50115 ProductionOrderExt extends "Production Order"
{
fields
{
field(50100; "ZY Test Field"; Text[100])
{
Caption = 'ZY Test Field';
DataClassification = CustomerContent;
}
}
}
pageextension 50115 FirmPlannedProdOrderExt extends "Firm Planned Prod. Order"
{
layout
{
addafter("Description 2")
{
field("ZY Test Field"; Rec."ZY Test Field")
{
ApplicationArea = All;
Caption = 'ZY Test Field';
ToolTip = 'This is a test field for demonstration purposes.';
}
}
}
}
tableextension 50116 ProdOrderLineExt extends "Prod. Order Line"
{
fields
{
field(50100; "ZY Test Field"; Text[100])
{
Caption = 'ZY Test Field';
DataClassification = CustomerContent;
}
}
}
pageextension 50116 FirmPlannedProdOrderLinesExt extends "Firm Planned Prod. Order Lines"
{
layout
{
addafter("Item No.")
{
field("ZY Test Field"; Rec."ZY Test Field")
{
ApplicationArea = All;
Caption = 'ZY Test Field';
ToolTip = 'This is a test field for demonstration purposes.';
}
}
}
}
END
Hope this will help.
Thanks for reading.
ZHU




コメント