BCApps icon indicating copy to clipboard operation
BCApps copied to clipboard

[Bug]: [Excel Reports] Vendor and Customer Top List reports fail with NavInvalidFilterExpressionException when a No. in the top N contains an apostrophe

Open Franco111000 opened this issue 2 months ago • 3 comments

Describe the issue

Report 4404 "EXR Vendor Top List" (Vendor - Top List (Excel)) and report 4409 "EXR Customer Top List" (Customer - Top List (Excel)) fail with Microsoft.Dynamics.Nav.Types.Exceptions.NavInvalidFilterExpressionException whenever a Vendor No. or Customer No. that ranks inside the requested top N contains an apostrophe.

In the web client the user only sees the generic page "Something went wrong. / An error has occurred." with a date and an operation id, no error text. The exception is thrown in OnPreReport, so the report produces nothing at all, not a partial dataset.

Root cause

Both reports build a quoted filter string by hand and never escape a quote inside the value. src/Apps/W1/ExcelReports/App/src/Vendor/EXRVendorTopList.Report.al:198 on current main:

local procedure EscapeVendorNoFilter(VendorNo: Code[20]): Text
begin
    exit('''' + VendorNo + '''');
end;

For a vendor numbered O'BRIEN LOGISTICS this produces the token 'O'BRIEN LOGISTICS', which the filter parser cannot read. Call sites:

  • :175 and :192: VendorFilter += EscapeVendorNoFilter(...) + '|', building the OR list of the top N
  • :215 and :235: EXTTopVendor*.SetFilter(Vendor_No, VendorFilter), where the exception is raised
  • :219 and :239: TopVendorData.SetFilter("Vendor No.", EscapeVendorNoFilter(...))

The same defect exists in src/Apps/W1/ExcelReports/App/src/Customer/EXRCustomerTopList.Report.al: EscapeCustomerNoFilter at :197, called at :174, :191, :218 and :238.

Two details make this look intermittent and impossible to work around from the request page:

  • It is rank dependent. With Quantity below the offending vendor's rank the report runs correctly; from that rank upward it always fails. On one environment Quantity 5 produced a correct workbook and Quantity 6 failed, the only difference being one more vendor entering the list.
  • The request page's own Vendor No. filter does not help. TransferFilters (:258 to :295) passes only Global Dimension 1 and 2, Currency Code, Vendor Posting Group and Date Filter to the two queries. Vendor No. is never transferred, so the top N is always computed over every vendor, and filtering to or excluding a single vendor changes nothing. Verified: Quantity 10 with the Vendor No. filter set to a vendor without an apostrophe still fails.

Expected behavior

Both reports render for any valid Vendor No. or Customer No., including values containing an apostrophe, and the vendor or customer appears in the list.

Suggested fix: double the quote inside the helper in both reports, for example:

exit('''' + VendorNo.Replace('''', '''''') + '''');

The two single-value call sites (:219 and :239, and their customer counterparts) could instead use the parameterised form SetFilter("Vendor No.", '%1', VendorNo) and skip string building entirely.

Steps to reproduce

  1. BC 28.4 sandbox with CRONUS demo data, any localisation.
  2. Create a vendor with an apostrophe in the No., for example O'BRIEN LOGISTICS.
  3. Post a purchase invoice for it, large enough that it lands inside the top 10 by Purchases (LCY), for example 250,000.
  4. Run report 4404 "Vendor - Top List (Excel)": Show = Purchases (LCY), Quantity = 10, Download.
  5. Actual: "Something went wrong. / An error has occurred." (NavInvalidFilterExpressionException in the server log). Expected: the report renders with that vendor in the list.
  6. Same with report 4409 "Customer - Top List (Excel)" and a customer numbered D'ANGELO RETAIL.

Additional context

BC 28.4 SaaS sandbox. Base Application 28.4.53241.54183, Dynamics BC Excel Reports 28.4.53241.53921. Reproducible with the built-in Excel layout and any Quantity that reaches the offending vendor or customer.

The pattern is unchanged on main; the last commit touching either file is #7402 (2026-03-30, CodeCop rule changes only). No other report in the Excel Reports app builds a filter this way.

Request page as run (Quantity 10, no Vendor No. filter):

Image

Resulting error page in the web client:

Image

The tenant id and operation id of the failing run are available on request.

I will provide a fix for a bug

  • [x] I will provide a fix for a bug

Franco111000 avatar Sep 10 '26 14:09 Franco111000

:robot: AI triage completed. Product group, please validate the triage report (Microsoft internal access only, use Ctrl+Click to open in new tab).


Was this triage helpful? React with :thumbsup: or :thumbsdown: on this comment to provide feedback.

github-actions[bot] avatar Sep 10 '26 14:09 github-actions[bot]

Clearly a bug. Approved!

JesperSchulz avatar Nov 04 '26 14:11 JesperSchulz

Thanks @JesperSchulz ! The pull request is up: #13680.

One change from the issue: the line I suggested there does not compile on Code[20], so the helper now takes Text, and the single-value lookups use SetRange.

Franco111000 avatar Nov 04 '26 18:11 Franco111000