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
- Create a new Vendor and fill in the following fields:
- Name = random string A
- Address = random string B
- 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
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.Expected behavior
The procedure should return the Vendor found by name:
Steps to reproduce
Additional context
No response
I will provide a fix for a bug