Skip to content
SETFILTER issue with special characters in Business Central

Why SETFILTER doesn’t work sometimes

Daniel Gorski
Daniel Gorski May 04, 2023
1 min read

Every AL-Developer uses “SETFILTER” on a daily basis. But did you know that there are certain situations where “SETFILTER” will refuse to work?

First let’s look at the syntax:

Rec.SETFILTER(<Field>, <Filter>, <Placeholders>);

Seems simple enough right?

AL code calling Rec.SetFilter on the Name field with a placeholder filter '<>%1' and the value 'Adatum*'

This will work just fine. But what happens if we do the following?

AL code calling Rec.SetFilter with the wildcard characters '@' and '' placed directly in the filter expression '<>@%1'

The applied filter will look like this:

Customer list with the Name filter showing the unresolved placeholder text '<>@%1', so Adatum Corporation still appears at the top instead of being excluded

AL did not manage to replace the placeholders inside the filter string, because “*” and “@” are used.

To make this work, we must use “STRSUBSTNO”:

STRSUBSTNO('<Filter>', <Values>)

That way, we construct the filter-text by ourselves and pass it into the filter string of the SETFILTER function. The result will look like this:

Customer list with the filter correctly built via StrSubstNo as '<>@Adatum', now excluding Adatum Corporation from the results

Related posts

▸ All posts
Upload and download files via BLOB in Business Central

Upload and Download Files in a BC Blob Field

January 29, 2025 · Daniel Gorski

Learn how to upload and download files in Business Central using a custom AL page and a BLOB field—perfect for storing documents, images, and more.

Read More
Read More: How to Upload and Download Files in a Blob Field in Business Central
Business Central performance tips from BC TechDays

Performance Giveaways

September 19, 2022 · Daniel Gorski

Inspired by Waldo’s BC TechDays 2022 session – discover 5 practical AL coding tips to boost performance in Microsoft Dynamics 365 Business Central.

Read More
Read More: Performance Giveaways
Split multiline comments in Business Central

Split Multiline Text into Records

June 28, 2022 · Daniel Gorski

Learn how to split long multiline text into comment records in Business Central using AL and Regex — including a working editor example and useful patterns.

Read More
Read More: Split Multiline Text into Records