Case: Add custom step to License Plate on Packing

Minimum Requirements

  • Mobile WMS 5.52 (or newer)

Case

A customer wishes to start capturing the Temperature during the Packing Process for some specific License Plate types.
Create customization to set up, collect and save the temperature in the Packing process.


The setup must be added to the Package Setup table and the captured values must be written to the License Plate table.


Proposed solution

You must add a new field to the Package Setup Table, to allow the customer to specify which type of License Plates the Temperature must be registered for.
Add a new Decimal collector step to register the Temperature for the License Plate. Save the collected Temperature value to a new field in the License Plate table.


And last but not least, ensure existing rules about required values in the Package Setup table are handled correctly in the Packing Page on the mobile device.

Example code

Define a new field to hold data

tableextension 50101 "MOB Case PackageSetupExt" extends "MOB Mobile WMS Package Setup"
{
    fields
    {
        field(50100; "MOB Register Temperature"; Boolean)
        {
            Caption = 'Register Temperature';
            DataClassification = CustomerContent;
        }
        field(50101; "MOB Default Temperature"; Decimal)
        {
            Caption = 'Default Temperature';
            DataClassification = CustomerContent;
            DecimalPlaces = 0 : 5;
            MinValue = 0;
        }
    }
}

pageextension 50101 "MOB Case PackageSetupExt" extends "MOB Mobile WMS Package Setup"
{
    layout
    {
        addafter(RegisterHeight)
        {
            field("RegisterTemperature"; Rec."MOB Register Temperature")
            {
                ApplicationArea = All;
                ToolTip = 'Specifies if the Temperature should be registered';
            }
            field("DefaultTemperature"; Rec."MOB Default Temperature")
            {
                ApplicationArea = All;
                ToolTip = 'Specifies the default Temperature';
            }
        }
    }
}

Define new fields to setup if Temperature should be registered and specify an optional default value


tableextension 50100 "MOB Case LicensePlateExt" extends "MOB License Plate"
{
    fields
    {
        field(50100; "MOB Temperature"; Decimal)
        {
            Caption = 'Temperature';
            DataClassification = CustomerContent;
            DecimalPlaces = 0 : 5;
            MinValue = 0;
        }
    }
}

pageextension 50100 "MOB Case LicensePlateExt" extends "MOB License Plate"
{
    layout
    {
        addafter(Height)
        {
            field("Temperature"; Rec."MOB Temperature")
            {
                ApplicationArea = All;
                ToolTip = 'Specifies the Temperature';
            }
        }
    }
}

Define the new step based on Package Setup


Using this event to add steps

  

    /// <summary>
    /// Add a new Step for your own Custom Field 'Temperature'
    /// </summary>    
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Adhoc Registr.", 'OnPostAdhocRegistration_OnAddSteps', '', true, true)]
    local procedure OnPostAdhocRegistration_OnAddSteps(_RegistrationType: Text; var _RequestValues: Record "MOB NS Request Element"; var _Steps: Record "MOB Steps Element"; var _RegistrationTypeTracking: Text)
    begin



        if not (_RegistrationType in ['PackagesToShipLookup', 'BulkRegPackageInfo']) then
            exit;

        // Break if our step is already collected to prevent infinite loop
        if _RequestValues.HasValue('Temperature') then
            exit;

        AddMyExtraSteps(_Steps, _RequestValues);
    end;

    /// <summary>
    /// Helper Function to insert Custom Step 'Temperature' based on Package Setup table
    /// </summary>    
    local procedure AddMyExtraSteps(var _Steps: Record "MOB Steps Element"; var _RequestValues: Record "MOB NS Request Element")
    var
        PackageSetup: Record "MOB Mobile WMS Package Setup";
        LicensePlate: Record "MOB License Plate";
    begin

        GetPackageSetup(LicensePlate, PackageSetup, _RequestValues);

        if PackageSetup."MOB Register Temperature" then begin
            _Steps.Create_DecimalStep(100000, 'Temperature');
            _Steps.Set_header('Temperature');
            _Steps.Set_helpLabel('Enter Temperature:');
            if LicensePlate.Temperature <> 0 then
                _Steps.Set_defaultValue(LicensePlate.Temperature)
            else
                _Steps.Set_defaultValue(PackageSetup."MOB Default Temperature");
            _Steps.Save();
        end;
    end;

    /// <summary>
    /// Helper Function to Identify and return License Plate and Package Setup based on RequestValues as input
    /// </summary>
    local procedure GetPackageSetup(var _LicensePlate: Record "MOB License Plate"; var _PackageSetup: record "MOB Mobile WMS Package Setup"; var _RequestValues: Record "MOB NS Request Element")
    var
        PackageType: Record "MOB Package Type";
        WhseShipmentHeader: Record "Warehouse Shipment Header";
        PackageTypeCode: Code[100];
        LicensePlateNo: Code[20];
        BackendID: Text;
    begin
        Evaluate(BackendID, _RequestValues.GetValue('BackendID'));
        Evaluate(PackageTypeCode, _RequestValues.GetValue('PackageType'));
        Evaluate(LicensePlateNo, _RequestValues.GetValue('LicensePlate'));



        // Try to get the 'Shipping Agent'
        if not WhseShipmentHeader.Get(BackendID) or (WhseShipmentHeader."Shipping Agent Code" = '') then
            exit;

        // Try to get the 'Package Type'
        if not PackageType.Get(PackageTypeCode) then
            exit;

        // Try to find the specific setup for the combination of 'Shipping Agent' and 'Package Type'
        if not _PackageSetup.Get(WhseShipmentHeader."Shipping Agent Code", PackageType.Code) then
            exit;

        // Try to get the License Plate
        if not _LicensePlate.Get(LicensePlateNo) then
            exit;
    end;

Handle the collected value from the steps and store data.

Using two different events to support both single and Batch registration on License Plate

    /// <summary>
    /// Transfer collected value from Custom Step 'Temperature' to a custom Field 'Temperature' on the License Plate
    /// </summary>  
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Pack Adhoc Reg", 'OnPostAdhocRegistrationOnPackagesToShip_OnAfterUpdateLicensePlate', '', false, false)]  //
    local procedure OnPostAdhocRegistrationOnPackagesToShip_OnAfterUpdateLicensePlate(var _LicensePlate: Record "MOB License Plate"; var _RequestValues: Record "MOB NS Request Element")
    var
        TemperatureValue: Decimal;
    begin
        TemperatureValue := _RequestValues.GetValueAsDecimal('Temperature');



        if TemperatureValue <> 0 then begin
            _LicensePlate.Validate(Temperature, TemperatureValue);
            _LicensePlate.Modify()
        end;
    end;

    /// <summary>
    /// Transfer collected value from Custom Step used in Bulk Registration to Field on License Plate
    /// </summary>  
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Pack Adhoc Reg", 'OnPostAdhocRegistrationOnBulkRegPackageInfo_OnAfterUpdateLicensePlate', '', false, false)]  //
    local procedure OnPostAdhocRegistrationOnBulkRegPackageInfo_OnAfterUpdateLicensePlate(var _LicensePlate: Record "MOB License Plate"; var _RequestValues: Record "MOB NS Request Element")
    var
        TemperatureValue: Decimal;
    begin
        TemperatureValue := _RequestValues.GetValueAsDecimal('Temperature');

        if TemperatureValue <> 0 then begin
            _LicensePlate.Validate("MOB Temperature", TemperatureValue);
            _LicensePlate.Modify()
        end;
    end;


Check if Temperature has been registered and determine if the License Plate can be marked as "ready" (green checkmark)

Using this event to check if required package Info is collected

    

    /// <summary>
    /// Check if your custom Field 'Temperature" is required in the current Package Setup and set the value of the "PackageInfoColled" flag (determine if a Green Checkmark is shown)  
    /// </summary>  
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB License Plate Mgt", 'OnCheckLicensePlatePackageInfo', '', false, false)]
    local procedure OnCheckLicensePlatePackageInfo(_LicensePlate: Record "MOB License Plate"; _PackageSetup: Record "MOB Mobile WMS Package Setup"; var _IsPackageInfoCollected: Boolean)
    begin
        // Default value for _IsPackingInfoCollected is true

        if _IsPackageInfoCollected = false then
            exit;

        if _PackageSetup."MOB Register Temperature" and (_LicensePlate.Temperature = 0) then
            _IsPackageInfoCollected := false
    end;

Determine if the new Field Temperature should be Cleared, based on changed Package Setup if either the Shipping Agent or Package Type are changed.

Using this even to clean up

OnPostAdhocRegistrationOnPackagesToShip_OnUpdateLicensePlateFromPackageSetup

    /// <summary>
    /// Handle cleanup for your own Custom Field 'Temperature' on License Plate when Package Setup changes.
    /// Package Setup will change when an other Shipping Agent or Package Type is selected
    /// </summary>    
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Pack Adhoc Reg", 'OnPostAdhocRegistrationOnPackagesToShip_OnUpdateLicensePlateFromPackageSetup', '', false, false)]
    local procedure OnPostAdhocRegistrationOnPackagesToShip_OnAfterUpdateLicensePlateFromPackageSetup(var _LicensePlate: Record "MOB License Plate"; _PackageSetup: Record "MOB Mobile WMS Package Setup")
    begin

        if _PackageSetup."Package Type" = '' then  // No PackageSetup available
            Clear(_LicensePlate.Temperature);

        if not _PackageSetup."MOB Register Temperature" then
            Clear(_LicensePlate.Temperature);
    end;

Test your solution

Start by manually updating the new fields in the Package Setup Page for any package type in Business Central.
Select the Pack & Ship menu on the mobile device and select Warehouse Shipment to Pack.

After selecting a 'Package Type with the new field "Register Temperatur" enabled in the Package Setup, you should be presented with the new step before the line turns "green".
After the line changes to "green" check the License Plate Page in Business Central to make sure the collected values have been saved to the new Temperature field.

As the final test, you must change the 'Package Type' to one without "Register Temperature" enabled on the mobile device. Then go back to BC and check that the value is cleared in the Temperature field on the License plate Page.