Versions Compared

Key

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

Use this event to

...

Use this event to

Excerpt

Handle a Lookup request for a custom LookupType.

...


Supersedes OnLookupOnCustomLookupTypeAsXml and OnLookupOnCustomLookupType (MOB5.21 - MOB5.28)

Sample request

...

Sample request

<request name="Lookup">
          <ItemNumber>1980-s</ItemNumber>
          <LookupType>MyCustomSubstituteItems</LookupType>
    </requestData>
</request>

Template

    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Lookup", 'OnLookupOnCustomLookupType''', true, true)]
    local procedure OnLookupOnCustomLookupType(_MessageId: Guid; _LookupType: Textvar _RequestValues: Record "MOB NS Request Element"; var _LookupResponseElement: Record "MOB NS WhseInquery Element"; var _RegistrationTypeTracking: Textvar _IsHandled: Boolean)
    begin
    end;

...

" created="2018-12-06T15:23:00+01:00" xmlns="http://schemas.microsoft.com/Dynamics/Mobile/2007/04/Documents/Request">
     <requestData name="Lookup">
          <ItemNumber>1980-s</ItemNumber>
          <LookupType>MyCustomSubstituteItems</LookupType>
    </requestData>
</request>

Template

    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Lookup", 'OnLookupOnCustomLookupType''', true, true)]
    local procedure MyOnLookupOnCustomLookupType OnLookupOnCustomLookupType(_MessageId: Guid; _LookupType: Textvar _RequestValues: Record "MOB NS Request Element"; var _LookupResponseElement: Record "MOB NS WhseInquery Element"; var _RegistrationTypeTracking: Textvar _IsHandled: Boolean)
    begin
        if _LookupType = 'MyCustomSubstituteItems' then begin
            if _IsHandled then
                exit; var _LookupResponseElement: Record "MOB NS WhseInquery Element"; var  MyCustomLookupSubstituteItems(_RequestValues, _LookupResponseElement);
            _IsHandled := true;
        end;RegistrationTypeTracking: Textvar _IsHandled: Boolean)
    begin
    end;    local procedure MyCustomLookupSubstituteItems(var _RequestValues: Record "MOB NS Request Element"; var _LookupResponseElement: Record "MOB NS WhseInquery Element")
    var
        ItemSubstitution: Record "Item Substitution";
        MobWmsLookup: Codeunit "MOB WMS Lookup";
        MobToolbox: Codeunit "MOB Toolbox";
        MobWmsToolbox: Codeunit "MOB WMS Toolbox";
        MobXmlMgt: Codeunit "MOB Xml Management";
        MobItemReferenceMgt: Codeunit "MOB Item Reference Mgt.";
        ScannedItemNumber: Text;
        ItemNumber: Code[20];
        VariantCode: Code[10];
    begin
        // Read Request
        ScannedItemNumber := _RequestValues.GetValue('ItemNumber', true);
        ItemNumber := MobItemReferenceMgt.SearchItemReference(CopyStr(MobToolbox.ReadEAN(ScannedItemNumber)150), VariantCode);
        // Determine if the item has substitutes
        ItemSubstitution.SetRange("No.", MobWmsToolbox.GetItemNumber(ItemNumber));
        ItemSubstitution.SetRange("Variant Code", VariantCode);
        if ItemSubstitution.FindSet() then
            repeat
                // Collect the buffer values for the <LookupResponse> element
                _LookupResponseElement.Create();
                MyCustomSetFromLookupSubstituteItem(ItemSubstitution, _LookupResponseElement);
                _LookupResponseElement.Save();
            until ItemSubstitution.Next() 0;
    end;
    local procedure MyCustomSetFromLookupSubstituteItem(_ItemSubstitution: Record "Item Substitution"; var _LookupResponseElement: Record "MOB NS WhseInquery Element")
    var
        Item: Record Item;
        ItemVariant: Record "Item Variant";
        MobWmsLookup: Codeunit "MOB WMS Lookup";
        MobWmsLanguage: Codeunit "MOB WMS Language";
        MobWmsToolbox: Codeunit "MOB WMS Toolbox";
        LineBuf: array[10of Text[250];
    begin
        Item.Get(_ItemSubstitution."Substitute No.");
        // Populate LineBuf[1] and LineBuf[2] from details about the substitute
        Clear(LineBuf);
        if (_ItemSubstitution."Substitute Variant Code" <> '') and (ItemVariant.Get(_ItemSubstitution."Substitute No.", _ItemSubstitution."Substitute Variant Code")) then
            MobWmsLookup.GetText(ItemVariant.Description, ItemVariant."Description 2", LineBuf)
        else
            MobWmsLookup.GetText(Item.Description, Item."Description 2", LineBuf);
        _LookupResponseElement.Init();
        


Example

    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Lookup", 'OnLookupOnCustomLookupType''', true, true)]
    local procedure MyOnLookupOnCustomLookupType(_MessageId: Guid; _LookupType: Textvar _RequestValues: Record "MOB NS Request Element"; var _LookupResponseElement: Record "MOB NS WhseInquery Element"; var _RegistrationTypeTracking: Textvar _IsHandled: Boolean)
    begin
        if _LookupType = 'MyCustomSubstituteItems' then begin
            if _IsHandled then
                exit;

            MyCustomLookupSubstituteItems(_RequestValues, _LookupResponseElement);

            _IsHandled := true;
        end;
    end;

    local procedure MyCustomLookupSubstituteItems(var _RequestValues: Record "MOB NS Request Element"; var _LookupResponseElement: Record "MOB NS WhseInquery Element")
    var
        ItemSubstitution: Record "Item Substitution";
        MobWmsLookup: Codeunit "MOB WMS Lookup";
        MobToolbox: Codeunit "MOB Toolbox";
        MobWmsToolbox: Codeunit "MOB WMS Toolbox";
        MobXmlMgt: Codeunit "MOB Xml Management";
        MobItemReferenceMgt: Codeunit "MOB Item Reference Mgt.";
        ScannedItemNumber: Text;
        ItemNumber: Code[20];
        VariantCode: Code[10];
    begin
        // Read Request
        ScannedItemNumber := _RequestValues.GetValue('ItemNumber', true);
        ItemNumber := MobItemReferenceMgt.SearchItemReference(CopyStr(MobToolbox.ReadEAN(ScannedItemNumber)150), VariantCode);

        // Determine if the item has substitutes
        ItemSubstitution.SetRange("No.", MobWmsToolbox.GetItemNumber(ItemNumber));
        ItemSubstitution.SetRange("Variant Code", VariantCode);

        if ItemSubstitution.FindSet() then
            repeat
                // Collect the buffer values for the <LookupResponse> element
                _LookupResponseElement.Create();
                MyCustomSetFromLookupSubstituteItem(ItemSubstitution, _LookupResponseElement);
                _LookupResponseElement.Save();
            until ItemSubstitution.Next() 0;
    end;

    localprocedure MyCustomSetFromLookupSubstituteItem(_ItemSubstitution: Record "Item Substitution"; var _LookupResponseElement: Record "MOB NS WhseInquery Element")
    var
        MobWmsLookup: Codeunit "MOB WMS Lookup";
        MobWmsLanguage: Codeunit "MOB WMS Language";
        MobWmsToolbox: Codeunit "MOB WMS Toolbox";
    begin
        _LookupResponseElement.Init();



        _LookupResponseElement.Set_Location('');
                _LookupResponseElement.Set_ItemNumber(_ItemSubstitution."Substitute NoSubstitute No.");
                _LookupResponseElement.Set_Barcode('');

                _LookupResponseElement.Set_SerialNumber('');
                _LookupResponseElement.Set_LotNumber('');
                _LookupResponseElement.Set_Bin('');
                _LookupResponseElement.Set_Quantity(1);
                _LookupResponseElement.Set_UoM('');
                _LookupResponseElement.SetValue('MyCustomValue',  'My Custom ValueMy Custom Value');
        

        _LookupResponseElement.Set_DisplayLine1(_LookupResponseElement.Get_ItemNumber());
                _LookupResponseElement.Set_DisplayLine2(LineBuf[1]MobWmsToolbox.GetItemAndVariantDescription(_ItemSubstitution."Substitute No.", _ItemSubstitution."Substitute Variant Code"));
                _LookupResponseElement.Set_DisplayLine3(LineBuf[2]'');
                _LookupResponseElement.Set_DisplayLine4(_ItemSubstitution."Substitute Variant CodeSubstitute Variant Code"  <> <> '',  MobWmsLanguageMobWmsLanguage.GetMessage('VARIANT_LABEL')  +  '   '  +   _ItemSubstitution."Substitute Variant CodeSubstitute Variant Code",  '');
                _LookupResponseElement.Set_DisplayLine5('Interchangeable:   '  +  MobWmsToolboxMobWmsToolbox.Bool2TextAsDisplayFormat(_ItemSubstitution.Interchangeable));
        _LookupResponseElement.Set_ExtraInfo1('');
        _LookupResponseElement.Set_ExtraInfo2('');
        _LookupResponseElement.Set_ExtraInfo3('');

                _LookupResponseElement.Set_ReferenceID(_ItemSubstitution);
        end;


Version History

VersionChanges
MOB5.38GetText replaced with new MobWmsToolbox.GetItemAndVariantDescription
MOB5.29New Parameter LookupResponseElement (replacering existing parameter XmlResultDoc)
MOB5.21Introduced