Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Case

When receiving goods, a new text collector step must be added for the user to enter comments about goods being damaged etc.
The step must appear when the document is posted. Usage is optional.


Proposed solution

Add a new text collector steps on header for inbound goods documents (Warehouse Receipts, Purchase Orders, SalesReturnOrders, but exclude inbound transfers).


Save collected values for SalesReturnOrders to Sales Comment Line before posting (saving values for Warehouse Receipts and Purchase Orders not implemented in this example).
Note: SalesReturnOrders is for nonwarehouse locations only (ie. Cronus 'BLUE'). Sales return orders for Warehouse locations is warehouse receipts in standard BC (ie. Cronus 'WHITE').


Example

    //
    // Create new comment steps on header (displayed when posting the order)
    //
    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAddStepsToAnyHeader''', true, true)]
    procedure OnGetReceiveOrderLines_OnAddStepsToAnyHeader(_RecRef: RecordRefvar _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::CodeunitCodeunit::"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::CodeunitCodeunit::"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::CodeunitCodeunit::"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;

  • No labels