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 34 Current »

Requirements

Extension version MOB5.14

Helper methods for GetValueAsDecimal requires MOB5.23 (or newer). For versions MOB5.14-MOB5.22 rewrite to Evaluate(...)

Old version of this article (Legacy) Case: Add Line Steps to Warehouse Receipts (MOB5.11-MOB5.13)

Case

A customer wishes to start using Item NetWeight and -GrossWeight, but have currently no values registered at the Item Card. Create a temporary customization is to collect these weights 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 Code

Define new fields to hold data

tableextension 50665 "MOBDEMO Warehouse Receipt Line" extends "Warehouse Receipt Line"
{
    fields
    {
        field(50200; "MOBDEMO Captured NetWeight"; Decimal)
        {
            Description = 'Mobile WMS DEMO';
            Caption = 'Captured NetWeight';
            DataClassification = CustomerContent;
        }

        field(50201; "MOBDEMO Captured GrossWeight"; Decimal)
        {
            Description = 'Mobile WMS DEMO';
            Caption = 'Captured GrossWeight';
            DataClassification = CustomerContent;
        }
    }

}

tableextension 50666 "MOBDEMO Posted Whse. Rcpt. Li" extends "Posted Whse. Receipt Line"
{
    fields
    {
        field(50200; "MOBDEMO Captured NetWeight"; Decimal)
        {
            Description = 'Mobile WMS DEMO';
            Caption = 'Captured NetWeight';
            DataClassification = CustomerContent;
        }

        field(50201; "MOBDEMO Captured GrossWeight"; Decimal)
        {
            Description = 'Mobile WMS DEMO';
            Caption = 'Captured GrossWeight';
            DataClassification = CustomerContent;
        }
    }
}

 

Define the steps

Using event OnGetReferenceData_OnAddRegistrationCollectorConfigurations

    //
    // Create new RegistrationCollectorConfiguration-Key in reference data with two steps named: "CustomGrossWeightGrams" and "CustomNetWeightGrams"
    // 
    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Reference Data", 'OnGetReferenceData_OnAddRegistrationCollectorConfigurations''', true, true)]
    local procedure OnGetReferenceData_OnAddRegistrationCollectorConfigurations(var _Steps: Record "MOB Steps Element")
    begin
        _Steps.InitConfigurationKey('CustomReceiveSteps');



        _Steps.Create_DecimalStep(10000'CustomNetWeightGrams');
        _Steps.Set_header('Net Weight (Grams)');
        _Steps.Set_label('Net Weight (Grams):');
        _Steps.Set_helpLabel('Net Weight in Grams per Base Unit of Measure');
        _Steps.Set_minValue(0);
        _Steps.Set_maxValue(100000);
        _Steps.Set_performCalculation(true);

        _Steps.Create_DecimalStep(20000'CustomGrossWeightGrams');
        _Steps.Set_header('Gross Weight (Grams)');
        _Steps.Set_label('Gross Weight (Grams):');
        _Steps.Set_helpLabel('Gross Weight in Grams per Base Unit of Measure');
        _Steps.Set_minValue(0);
        _Steps.Set_maxValue(100000);
        _Steps.Set_performCalculation(true);
    end;


Include the steps on Receive Lines

Using event OnGetReceiveOrderLines_OnAddStepsToAnyLine    

    //
    // Add steps referenced by new RegistrationCollectorConfiguration-Key to line steps collectors
    //
    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAddStepsToAnyLine''', true, true)]
    local procedure OnGetReceiveOrderLines_OnAfterAddStepsOnAnyLine(_RecRef: RecordRefvar _BaseOrderLineElement: Record "MOB Ns BaseDataModel Element")
    begin
        // MOB5.11
        // Currently the Android Mobile App supports only one "RegisterExtraInfo"-node (one extra RegistrationCollectorConfigurationKey).
        // The last subscriber to OnGetReceiveOrderLines_OnAfterAddStepsByReferenceDataKey must set a <RegisterExtraInfo>-key that includes steps for all previous subscribers.
        // This is only possible by knowing what other customizations is done and manually create a new RegistrationCollectorConfigurationKey that includes all steps.
        // 

        // In this demo we expect to be only subscriber and throw an error if earlier subscribtions exists by including optional _ErrorIfAlreadyCreated parameter.
        // We cannot test if later subcribers is overriding this value we set.
        _BaseOrderLineElement.Create_StepsByReferenceDataKey('CustomReceiveSteps');
    end;

Handle the collected values from the steps. Storing data before posting.

Using event OnPostReceiveOrder_OnHandleRegistrationForWarehouseReceiptLine

    //
    // Handle new step input values by WhseReceiptLine (move captured values to new fields at Whse. Receipt Line)
    //
    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnHandleRegistrationForWarehouseReceiptLine''', true, true)]
    local procedure OnPostReceiveOrder_OnHandleRegistrationForWarehouseReceiptLine(var _Registration: Record "MOB WMS Registration"; var _WhseReceiptLine: Record "Warehouse Receipt Line")
    var
        RegistrationXmlText: Text;
    begin
        // Demo: Show content of the "Registration XML" blob -- not needed for the processing below (useful for debugging)
        RegistrationXmlText := _Registration.GetRegistrationXmlAsText();

        // Parse the xml WmsRegistration by name of the steps declared in GetOrderLineExtraInfoCDataSection() and save value to new fields at WhseReceiptLine
        // Includes optional parameter _ErrorIfNotExists since we unconditially expect these two nodes to exist at all line registrations
        _WhseReceiptLine."MOBDEMO Captured NetWeight" := _Registration.GetValueAsDecimal('CustomNetWeightGrams', true);
        _WhseReceiptLine."MOBDEMO Captured GrossWeight" := _Registration.GetValueAsDecimal('CustomGrossWeightGrams', true);
    end;


 Included the values in posting

Using base code event "OnBeforePostSourceDocument".   

    //
    // Push new fields at Warehouse Activity Line to Item card using standard posting event
    // Using this standard event ensures data written to Item is within same commit at Whse Receipt Line posting
    //
    [EventSubscriber(ObjectType::CodeunitCodeunit::"Whse.-Post Receipt", 'OnBeforePostSourceDocument''', true, true)]
    local procedure OnWhsePostReceiptOnBeforePostSourceDocument(var WhseRcptLine: Record "Warehouse Receipt Line"; PurchaseHeader: Record "Purchase Header"; SalesHeader: Record "Sales Header"; TransferHeader: Record "Transfer Header")
    var
        Item: Record Item;
    begin
        if not (Item.Get(WhseRcptLine."Item No.") and ((WhseRcptLine."MOBDEMO Captured NetWeight" <> 0) or (WhseRcptLine."MOBDEMO Captured GrossWeight" <> 0))) then
            exit;

        UpdateItemWeights(Item, WhseRcptLine."MOBDEMO Captured NetWeight", WhseRcptLine."MOBDEMO Captured GrossWeight");
        Item.Modify();
    end;

    local procedure UpdateItemWeights(var _Item: Record Item; _NetWeightGrams: Integer; _GrossWeightGrams: Integer)
    var
        ConversionFactor: Decimal;
    begin
        // Conversion factor between registrered unit (grams) and item card unit (kg) -- hardcoded for simplification
        ConversionFactor := 1000;

        // Update item card if new values was provided in the input steps
        if _GrossWeightGrams > 0 then
            _Item."Gross Weight" := _GrossWeightGrams / ConversionFactor;

        if _NetWeightGrams > 0 then
            _Item."Net Weight" := _NetWeightGrams / ConversionFactor;
    end;

}

Test your solution

  • Register a Warehouse Receipt at a Mobile Device. Two new line steps for NetWeight and GrossWeight should appear. Add both Weights for an item and post the Receipt.

  • Run table browser for Posted Whse. Receipt Line (table no. 7319). Your new values should be visible at latest posted receipt:

  • Run table browser for Item (table no. 27). Your new values should be recorded at the Item you registered/posted:

Version History

VersionChanges
MOB5.14Required events introduced (succeeds legacy version (Legacy) Case: Add Line Steps to Warehouse Receipts (MOB5.11-MOB5.13)).
  • No labels