Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Description

Excerpt

Online Validation on Steps can instantly validate the user -entered data, with a call to the backend

To reject the inputted data, write code to throw an Error.

...

BC. 


Use cases

  • Tell the user instantly whether an input value is correct
  • Return more additional steps
  • Return value(s) to other existing steps


@See also


Overview

Table of Contents
maxLevel2
minLevel2
excludeDescription

Tip

  • When working with Online Validation requests, use the Use Mobile Doc. Queue to view inspect the entire incoming request XML available for validation

...

     // Add Mobile Document Types
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Setup Doc. Types", 'OnAfterCreateDefaultDocumentTypes', '', true, true)]
    localprocedure My01OnAfterCreateDefaultDocumentTypes()
    var
        MobWmsSetupDocTypes: Codeunit"MOB WMS Setup Doc. Types";
    begin
        // Create and name document types
        MobWmsSetupDocTypes.CreateDocumentType('ValidateMyLotNumber', '', Codeunit::"MOB WMS Whse. Inquiry");
        MobWmsSetupDocTypes.CreateDocumentType('ValidateMySerial', '', Codeunit::"MOB WMS Whse. Inquiry");
        MobWmsSetupDocTypes.CreateDocumentType('ValidateMyToBin', '', Codeunit::"MOB WMS Whse. Inquiry");
        MobWmsSetupDocTypes.CreateDocumentType('ValidateMyFromBin', '', Codeunit::"MOB WMS Whse. Inquiry");
        MobWmsSetupDocTypes.CreateDocumentType('ValidateMyTote', '', Codeunit::"MOB WMS Whse. Inquiry");
        MobWmsSetupDocTypes.CreateDocumentType('ValidateMyQuantity', '', Codeunit::"MOB WMS Whse. Inquiry");
    end;

...

    // Write validation code
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Whse. Inquiry", 'OnWhseInquiryOnCustomDocumentType', '', true, true)]
    localprocedure My01OnWhseInquiryOnCustomDocumentType(_DocumentType: Text; var _RequestValues: Record"MOB NS Request Element"; var _ResponseElement: Record"MOB NS Resp Element"; var _RegistrationTypeTracking: Text; var _IsHandled: Boolean)
    begin
        if _IsHandled then
            exit;

        // Using ERROR() is the correct way to fail the validation, otherwise the validation was OK

        case _DocumentType of
            // These examples displays misc. request values for illustration purposes

            'ValidateMyLotNumber':
                Error('OrderNo: %1\ LineNo: %2\ LineItem: %3\ LotStep: %4\ ExpDateStep: %5',
                _RequestValues.Get_OrderBackendID(),
                _RequestValues.Get_LineNumber(),
                _RequestValues.Get_ItemNumber(), // Currently Not Supported by Android App 1.8.0.1
                _RequestValues.Get_LotNumber(),
                _RequestValues.Get_ExpirationDate()); // ExpirationDate-step will not trigger validation itself. But it is included when Lot-step is validated

            'ValidateMySerial':
                Error('OrderNo: %1\ LineNo:%2\ LineItem: %3\ SerialStep: %4',
                _RequestValues.Get_BackendID(),
                _RequestValues.Get_LineNumber(),
                _RequestValues.Get_ItemNumber(),
                _RequestValues.Get_SerialNumber());

            // Note: ToBin validation on receive must typically be enabled using "OnGetReceiveOrderLines_OnAfterSetFrom.." events
            'ValidateMyToBin':
                Error('OrderNo: %1\ LineNo:%2\ LineItem: %3\ BinStep: %4',
                _RequestValues.Get_OrderBackendID(),
                _RequestValues.Get_LineNumber(),
                _RequestValues.Get_ItemNumber(),
                _RequestValues.Get_Bin());

            'ValidateMyFromBin':
                Error('OrderNo: %1\ LineNo:%2\ LineItem: %3\ BinStep: %4',
                _RequestValues.Get_OrderBackendID(),
                _RequestValues.Get_LineNumber(),
                _RequestValues.Get_ItemNumber(),
                _RequestValues.Get_Bin());

            // Note: Tote is typically only used on Picking
            'ValidateMyTote':
                Error('OrderNo: %1\ LineNo: %2\ LineItem: %3\ ToteStep: %4',
                _RequestValues.Get_OrderBackendID(),
                _RequestValues.Get_LineNumber(),
                _RequestValues.Get_ItemNumber(), // Currently Not Supported by Android App 1.8.0.1
                _RequestValues.Get_ToteID());

            'ValidateMyQuantity':
                Error('OrderNo: %1\ LineNo: %2\ LineItem: %3\ QuantityStep: %4',
                _RequestValues.Get_OrderBackendID(),
                _RequestValues.Get_LineNumber(),
                _RequestValues.Get_ItemNumber(),
                _RequestValues.Get_Quantity());
        end;

        // Validation was OK
        _IsHandled := true;
    end;

...

    // Add Mobile DocumentType to handle validation code
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Setup Doc. Types", 'OnAfterCreateDefaultDocumentTypes', '', true, true)]
    localprocedure My02OnAfterCreateDefaultDocumentTypes()
    var
        MobWmsSetupDocTypes: Codeunit"MOB WMS Setup Doc. Types";
    begin
        MobWmsSetupDocTypes.CreateDocumentType('ValidateMyWorkflowStep', '', Codeunit::"MOB WMS Whse. Inquiry");
    end;

...

 // Implement DocumentType
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Whse. Inquiry", 'OnWhseInquiryOnCustomDocumentType', '', true, true)]
    localprocedure My02OnWhseInquiryOnCustomDocumentType(_DocumentType: Text; var _RequestValues: Record"MOB NS Request Element"; var _ResponseElement: Record"MOB NS Resp Element"; var _RegistrationTypeTracking: Text; var _IsHandled: Boolean)
    begin
        if _IsHandled then
            exit;


        if _DocumentType = 'ValidateMyWorkflowStep'then
            Error('MyTextStep: %1\ OrderNo: %2\ LineNo: %3',
              _RequestValues.GetValue('MyTextStep'),
              _RequestValues.Get_BackendID(),
              _RequestValues.Get_LineNumber());

        _IsHandled := true;
    end;

...

// Define step
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Reference Data", 'OnGetReferenceData_OnAddRegistrationCollectorConfigurations', '', true, true)]
    localprocedure My03OnGetReferenceData_OnAddRegistrationCollectorConfigurations(var _Steps: Record"MOB Steps Element")
    begin
        // Define a key to hold the step
        _Steps.InitConfigurationKey('MyPickStep');

        // Define a text step
        _Steps.Create_TextStep(10, 'MyTextStep');
        _Steps.Set_header('Header text');
        _Steps.Set_label('Label text');
        _Steps.Set_helpLabel('Help text');

        // Enabled Online Validation and setting a DocumentType
        _Steps.Set_onlineValidation('ValidateMyPickStep', true);
    end;

Step 2: Add steps to Pick-function

...

    // Add steps Pick Lines
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Pick", 'OnGetPickOrderLines_OnAddStepsToAnyLine', '', true, true)]
    localprocedure My03OnGetPickOrderLines_OnAddStepsToAnyLine(_RecRef: RecordRef; var _BaseOrderLineElement: Record"MOB NS BaseDataModel Element")
    begin
        _BaseOrderLineElement.Create_StepsByReferenceDataKey('MyPickStep', true);
    end;

Step 3: Create new DocumentType

    // Add Mobile DocumentType to handle validation code
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Setup Doc. Types", 'OnAfterCreateDefaultDocumentTypes', '', true, true)]
    localprocedure My03OnAfterCreateDefaultDocumentTypes()
    var
        MobWmsSetupDocTypes: Codeunit"MOB WMS Setup Doc. Types";
    begin
        MobWmsSetupDocTypes.CreateDocumentType('ValidateMyPickStep', '', Codeunit::"MOB WMS Whse. Inquiry");
    end;

...

    // Implement DocumentType
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Whse. Inquiry", 'OnWhseInquiryOnCustomDocumentType', '', true, true)]
    localprocedure My03OnWhseInquiryOnCustomDocumentType(_DocumentType: Text; var _RequestValues: Record"MOB NS Request Element"; var _ResponseElement: Record"MOB NS Resp Element"; var _RegistrationTypeTracking: Text; var _IsHandled: Boolean)
    begin
        if _IsHandled then
            exit;


        if _DocumentType = 'ValidateMyPickStep'then
            Error('MyTextStep: %1\ OrderNo: %2\ LineNo: %3',
              _RequestValues.GetValue('MyTextStep'),
              _RequestValues.Get_BackendID(),
              _RequestValues.Get_LineNumber());

        _IsHandled := true;
    end;

...

    // Turn off OverDeliveryValidation warning
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAfterSetFromAnyLine', '', true, true)]
    localprocedure My04OnGetReceiveOrderLines_OnAfterSetFromAnyLine(_RecRef: RecordRef; var _BaseOrderLineElement: Record"MOB NS BaseDataModel Element")
    begin
        _BaseOrderLineElement.Set_OverDeliveryValidation('None');
    end;

Step 3: Create new DocumentType

    // Add Mobile Document Types
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Setup Doc. Types", 'OnAfterCreateDefaultDocumentTypes', '', true, true)]
    localprocedure My04OnAfterCreateDefaultDocumentTypes()
    var
        MobWmsSetupDocTypes: Codeunit"MOB WMS Setup Doc. Types";
    begin
        // Create and name relevant validation document 
        MobWmsSetupDocTypes.CreateDocumentType('ValidateMyQuantity', '', Codeunit::"MOB WMS Whse. Inquiry");
    end;

...

    // Implement DocumentType

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Whse. Inquiry", 'OnWhseInquiryOnCustomDocumentType', '', true, true)]
    localprocedure My04OnWhseInquiryOnCustomDocumentType(_DocumentType: Text; var _RequestValues: Record"MOB NS Request Element"; var _ResponseElement: Record"MOB NS Resp Element"; var _RegistrationTypeTracking: Text; var _IsHandled: Boolean)
    var
        WarehouseReceiptLine: Record"Warehouse Receipt Line";
        PerformValidation: Boolean;
    begin
        if _IsHandled then
            exit;

        if _DocumentType <> 'ValidateMyQuantity'then// DocumentType is derived from <validation> node in application.cfg
            exit;

        // This code is only for Receive-service. Could be Pick, PutAway, Ship, Move etc.
        if _RequestValues.Get_OrderType() <> 'Receive'then// Ordertype is derived from <Service> node in application.cfg
            exit;

        // "Force" is only present when a dialog was Confirmed OK by user
        PerformValidation := (not _RequestValues.Get_Force()) and
                             // Get source document line being registered
                             WarehouseReceiptLine.Get(_RequestValues.Get_OrderBackendID(), _RequestValues.Get_LineNumber());

        if PerformValidation then
            if _RequestValues.Get_Quantity() > WarehouseReceiptLine."Qty. Outstanding (Base)"then
                // "ForceWarning:" will trigger the confirm dialog
                Error('ForceWarning:%1 is more than %2.\\Is this correct?', _RequestValues.Get_Quantity(), WarehouseReceiptLine."Qty. Outstanding (Base)");

        _IsHandled := true;
    end;


Filter by label (Content by label)
showLabelsfalse
showSpacefalse
titleSee also
cqllabel = "bc" and label in ( "onwhseinquiryoncustomdocumenttypeasxml" , "onlinevalidation" )