Skip to content

[Bug]: [E-Document] A matching vendor cannot be found by Name #7419

@georgepomazkov

Description

@georgepomazkov

Describe the issue

The following procedure is supposted to find a Vendor by matching name and/or address from an incoming e-document.

When it fails to match a Vendor by Address (AddressNearness < RequiredNearness()), but matches it by Name (NameNearness >= RequiredNearness()) it logs a notification saying that 'Vendor matched by name but not by address.', but it does not actually return the found Vendor.

codeunit 6109 "E-Document Import Helper"
{
    procedure FindVendorByNameAndAddressWithNotification(VendorName: Text; VendorAddress: Text; EDocEntryNoForNotification: Integer): Code[20]
    var
        Vendor: Record Vendor;
        RecordMatchMgt: Codeunit "Record Match Mgt.";
        EDocumentNotification: Codeunit "E-Document Notification";
        NameNearness: Integer;
        AddressNearness: Integer;
        MatchedByAddress: Boolean;
    begin
        Vendor.SetCurrentKey(Blocked);
        Vendor.SetLoadFields(Name, Address);
        if Vendor.FindSet() then
            repeat
                NameNearness := RecordMatchMgt.CalculateStringNearness(VendorName, Vendor.Name, MatchThreshold(), NormalizingFactor());
                if VendorAddress = '' then
                    AddressNearness := RequiredNearness()
                else
                    AddressNearness := RecordMatchMgt.CalculateStringNearness(VendorAddress, Vendor.Address, MatchThreshold(), NormalizingFactor());
                if NameNearness >= RequiredNearness() then begin
                    MatchedByAddress := AddressNearness >= RequiredNearness();
                    if MatchedByAddress then
                        exit(Vendor."No.");
                    if EDocEntryNoForNotification <> 0 then
                        EDocumentNotification.AddVendorMatchedByNameNotAddressNotification(EDocEntryNoForNotification);
                end;
            until Vendor.Next() = 0;
    end;
}

Expected behavior

The procedure should return the Vendor found by name:

...
if NameNearness >= RequiredNearness() then begin
   MatchedByAddress := AddressNearness >= RequiredNearness();
   if MatchedByAddress then
      exit(Vendor."No.");
   if EDocEntryNoForNotification <> 0 then
      EDocumentNotification.AddVendorMatchedByNameNotAddressNotification(EDocEntryNoForNotification);
   exit(Vendor."No.");   // <===

Steps to reproduce

  1. Create a new Vendor and fill in the following fields:
    • Name = random string A
    • Address = random string B
  2. Implement and run the following piece of code:
var
   EDocumentImportHelper: Codeunit "E-Document Import Helper";
   VendorName: Text;
   VendorAddress: Text;
   VendorNo: Code[20];
begin
   VendorName = 'random string A';   // 'random string A' value
   VendorAddress = 'random string C';   // a random string different from 'random string B'
   VendorNo := EDocumentImportHelper.FindVendorByNameAndAddressWithNotification(VendorName, VendorAddress, 0);
   Message(VendorNo);   // shows empty string
end;

Additional context

No response

I will provide a fix for a bug

  • I will provide a fix for a bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    AI-TriageManually trigger or re-trigger an AI triage assessmentIntegrationGitHub request for Integration area

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions