Skip to content

E-Document Import Helper: return vendor when matched by name but not address#7904

Open
jeffreybulanadi wants to merge 1 commit intomicrosoft:mainfrom
jeffreybulanadi:fix/7419-edocument-find-vendor-by-name-and-address
Open

E-Document Import Helper: return vendor when matched by name but not address#7904
jeffreybulanadi wants to merge 1 commit intomicrosoft:mainfrom
jeffreybulanadi:fix/7419-edocument-find-vendor-by-name-and-address

Conversation

@jeffreybulanadi
Copy link
Copy Markdown
Contributor

@jeffreybulanadi jeffreybulanadi commented Apr 30, 2026

Summary

FindVendorByNameAndAddressWithNotification in codeunit 6109 "E-Document Import Helper" iterates vendors looking for a name-and-address match. When a vendor's name meets the required nearness threshold but its address does not, the procedure logged a notification and then continued the loop without returning the vendor. At the end of the loop, the function fell through and returned an empty Code[20].

Fixes #7419

Root Cause

The if NameNearness >= RequiredNearness() branch handled the address-match case with an exit, but there was no exit after the name-only notification path:

if NameNearness >= RequiredNearness() then begin
    MatchedByAddress := AddressNearness >= RequiredNearness();
    if MatchedByAddress then
        exit(Vendor."No.");           // address match: exits correctly
    if EDocEntryNoForNotification <> 0 then
        EDocumentNotification.AddVendorMatchedByNameNotAddressNotification(EDocEntryNoForNotification);
    // BUG: no exit here -- falls through and continues the loop
end;

Fix

Add exit(Vendor."No.") after the notification call. The now-redundant MatchedByAddress local variable is also removed.

if NameNearness >= RequiredNearness() then begin
    if AddressNearness >= RequiredNearness() then
        exit(Vendor."No.");
    if EDocEntryNoForNotification <> 0 then
        EDocumentNotification.AddVendorMatchedByNameNotAddressNotification(EDocEntryNoForNotification);
    exit(Vendor."No.");  // fixed: return the name-matched vendor
end;

Tests

Three new tests are added to EDocHelperTest (codeunit 139799):

Test Scenario
FindVendorByNameAndAddressReturnsVendorWhenNameMatchesAddressDoesNot Reproduces the reported bug: vendor is returned when name matches but address does not
FindVendorByNameAndAddressReturnsVendorWhenBothNameAndAddressMatch Confirms the existing happy path (name + address both match) still works
FindVendorByNameAndAddressReturnsEmptyWhenNoNameMatches Confirms an empty result is returned when no vendor name is similar enough

@jeffreybulanadi jeffreybulanadi requested a review from a team as a code owner April 30, 2026 06:43
@github-actions github-actions Bot added AL: Apps (W1) Add-on apps for W1 From Fork Pull request is coming from a fork labels Apr 30, 2026
…address

When a vendor's name meets the required nearness threshold but its address
does not, FindVendorByNameAndAddressWithNotification logged a notification
but omitted the exit statement, causing the function to silently discard the
match and return an empty Code[20].

Add exit(Vendor.No.) after the notification call so the function returns the
vendor when matched by name. The unused MatchedByAddress local variable is
also removed.

Add three tests to EDocHelperTest covering:
- Vendor found by name when address does not match (the reported bug scenario)
- Vendor found when both name and address match (existing happy path)
- Empty result when no vendor name is similar enough

Fixes microsoft#7419
@jeffreybulanadi jeffreybulanadi force-pushed the fix/7419-edocument-find-vendor-by-name-and-address branch from 32bd2a4 to c5d5634 Compare April 30, 2026 06:53
@jeffreybulanadi jeffreybulanadi changed the title Fix FindVendorByNameAndAddressWithNotification not returning vendor matched by name E-Document Import Helper: return vendor when matched by name but not address Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1 From Fork Pull request is coming from a fork

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant