Invalid single-quote escaping in filter string

Properties
PC0019 Warning Design Code Fix Ignore Obsolete

Many AL developers attempt to set an is not empty filter by writing '<>''' as the filter expression. The intention is <>'' (not equal to the empty string), but the quote escaping produces a different value.

In AL string literals, a single quote is escaped by doubling it. The literal '<>''' has three quotes after the >: the first pair is one escaped quote character, and the third closes the string. The actual filter expression becomes <>' (not equal to a single quote) instead of <>'' (not equal to empty).

Two correct alternatives: escape the empty string properly with '<>''''', or avoid the escaping entirely with a placeholder ('<>%1', '').

Example

procedure SetCustomerFilter()
var
    Customer: Record Customer;
begin
    Customer.SetFilter("Customer Posting Group", '<>'''); // Invalid single-quote escaping in filter string [PC0019]
end;

Escape the quotes correctly:

procedure SetCustomerFilter()
var
    Customer: Record Customer;
begin
    Customer.SetFilter("Customer Posting Group", '<>''''');
end;

Or use a placeholder to avoid the escaping:

procedure SetCustomerFilter()
var
    Customer: Record Customer;
begin
    Customer.SetFilter("Customer Posting Group", '<>%1', '');
end;

When the diagnostic is reported

  • A SetFilter call passes the literal '<>''' as the filter expression.
  • A CalcFormula WHERE clause uses filter('<>''').

Code fix

The code fix replaces '<>''' with the correctly escaped '<>'''''.

See also