[Bug]: [Excel Reports] Vendor and Customer Top List reports fail with NavInvalidFilterExpressionException when a No. in the top N contains an apostrophe
Nobody has claimed this yet.
- Dominant language
- AL
- Stars
- 683
- Forks
- 459
- Avg merge
- 3d 26m
- Merged PRs (30d)
- 633
Description
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:
:175and:192:VendorFilter += EscapeVendorNoFilter(...) + '|', building the OR list of the top N:215and:235:EXTTopVendor*.SetFilter(Vendor_No, VendorFilter), where the exception is raised:219and: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(:258to: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
- BC 28.4 sandbox with CRONUS demo data, any localisation.
- Create a vendor with an apostrophe in the No., for example
O'BRIEN LOGISTICS. - Post a purchase invoice for it, large enough that it lands inside the top 10 by Purchases (LCY), for example 250,000.
- Run report 4404 "Vendor - Top List (Excel)": Show = Purchases (LCY), Quantity = 10, Download.
- Actual: "Something went wrong. / An error has occurred." (
NavInvalidFilterExpressionExceptionin the server log). Expected: the report renders with that vendor in the list. - 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):
Resulting error page in the web client:
The tenant id and operation id of the failing run are available on request.
I will provide a fix for a bug
- I will provide a fix for a bug
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with EscapeVendorNoFilter in src/Apps/W1/ExcelReports/App/src/Vendor/EXRVendorTopList.Report.al and EscapeCustomerNoFilter in the corresponding Customer report, then inspect the cited SetFilter call sites. Reproduce with vendor and customer numbers containing apostrophes; done means reports 4404 and 4409 render successfully and include those records in the top list.
Written by the indexing model from the issue text.
Assessment
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100