Case
A customer wishes to start using Item NetWeight and -GrossWeight, but have currently no values registered at the Item Card. A temporary customization is to be made to start filling in these values when goods are received.
The captured values must be written to the Item Card during posting.
Proposed solution
The customer is using Warehouse Receipts for inbound goods always. Two new Decimal collector steps must be added for the user to enter NetWeight and GrossWeight for the item.
The customization is to be used only for a limited time, and should be isolated / easy to remove later.
Save collected NetWeight/GrossWeight values to new fields at Warehouse Receipt Lines. Then, move the values to Item Card during standard BC posting to ensure changes to Item Card is written within correct scope (same COMMIT as Warehouse Receipt Line posting).
Standard CRONUS Location 'WHITE' can be used for testing the customization.
Example
//
// Create new comment steps on header (displayed when posting the order)
//
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAddStepsToAnyHeader', '', true, true)]
procedure OnGetReceiveOrderLines_OnAddStepsToAnyHeader(_RecRef: RecordRef; var _StepsElement: Record "MOB Steps Element")
begin
with _StepsElement do
if _RecRef.Number() in [Database::"Warehouse Receipt Header", Database::"Purchase Header", Database::"Sales Header"] then begin
Create_TextStep(
10000, // id
'MyCommentStep', // name
'Comment', // header
'Comment:', // label
'Your optional comment about the inbound goods', // helpLabel
'', // defaultvalue
80); // length
Set_primaryInputMethod('Control');
Set_optional(true);
end;
end;
//
// Save collected values prior to posting. OnBeforePostXXX-triggers will commit prior to posting, and code will need to be organized accordingly.
//
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnBeforePostWarehouseReceipt', '', true, true)]
procedure OnPostReceiveOrder_OnBeforePostWarehouseReceipt(var _OrderValues: Record "MOB Common Element"; var _WhseReceiptHeader: Record "Warehouse Receipt Header")
begin
// Not implemented in this example -- see OnPostReceiveOrder_OnBeforePostSalesReturnOrder
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnBeforePostPurchaseOrder', '', true, true)]
procedure OnPostReceiveOrder_OnBeforePostPurchaseOrder(var _OrderValues: Record "MOB Common Element"; var _PurchHeader: Record "Purchase Header")
begin
// Not implemented in this example -- see OnPostReceiveOrder_OnBeforePostSalesReturnOrder
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnBeforePostSalesReturnOrder', '', true, true)]
procedure OnPostReceiveOrder_OnBeforePostSalesReturnOrder(var _OrderValues: Record "MOB Common Element"; var _SalesReturnHeader: Record "Sales Header")
var
SalesCommmentLine: Record "Sales Comment Line";
CollectedComment: Text;
begin
CollectedComment := _OrderValues.GetValue('MyCommentStep');
if CollectedComment <> '' then
ReplaceSalesCommentLine(_SalesReturnHeader, 'MOBILEWMS', CopyStr(CollectedComment, 1, MaxStrLen(SalesCommmentLine.Comment)));
end;
//
// Local helper functions
//
local procedure ReplaceSalesCommentLine(_SalesHeader: Record "Sales Header"; _Code: Code[10]; _Comment: Text[80])
var
SalesCommmentLine: Record "Sales Comment Line";
NextLineNo: Integer;
begin
with SalesCommmentLine do begin
// Remove all existing comments for the _Code
_SalesHeader.TestField("No.");
SetRange("Document Type", _SalesHeader."Document Type");
SetRange("No.", _SalesHeader."No.");
SetRange("Document Line No.", 0);
SetRange(Code, _Code);
DeleteAll();
// Find next LineNo
SetRange(Code);
if FindLast() then
NextLineNo := "Line No." + 10000
else
NextLineNo := 10000;
// Init and insert the comment line
Init();
"Document Type" := _SalesHeader."Document Type";
"No." := _SalesHeader."No.";
Code := _Code;
"Line No." := NextLineNo;
Date := Today();
Comment := _Comment;
Insert();
end;
end;