microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
728 stars 241 forks source link

Behavior of selected operators on SetFilter together with a placeholder (%1) #7631

Closed Arthurvdv closed 6 months ago

Arthurvdv commented 7 months ago

1. Describe the bug When using a SetFilter with one of the operators *, @ or ?, the behavior of the %1 placeholder changes.

2. To Reproduce

pageextension 50100 "Customer List" extends "Customer List"
{
    trigger OnOpenPage()
    var
        Customer: Record Customer;
    begin
        Customer.SetFilter("VAT Registration No.", '*8');
        Message('A: Found %1 customers', Customer.Count());

        Customer.SetFilter("VAT Registration No.", '*%1', '8');
        Message('B: Found %1 customers', Customer.Count());

        Customer.SetFilter("VAT Registration No.", '%1', '*8');
        Message('C: Found %1 customers', Customer.Count());
    end;
}
A: Found 4 customers
B: Found 0 customers
C: Found 4 customers

In case of A) and C) the placeholder (%1) is replaced with the value 8. In case of B) the %1 isn't replaced, where the filter value is *%1 instead of becoming *8.

3. Expected behavior Should all three messages return the same value? Not sure of this is a deliberate behavior or an bug. In case the behavior is "by design", it would be great the include this in the documentation (Record.SetFilter(Any, Text [, Any,...]) Method) and maybe elaborate on why this design choice has been made.

4. Actual behavior It seems that the behavior of a placeholder(s) is different on depending on the use of the *, @ or ? operators. The other supported operators, <, <=, >, >=, <>, &, .., and | don't influence the behavior of placeholder(s).

5. Versions:

Final Checklist

Please remember to do the following:

pri-kise commented 7 months ago

I think this issue has been there since NAV. I can rember that I changed there some filter because of this behaviour. Additionally I think that this is more a plattform issue and less a compiler issue. Therefore this issue will be closed for this reason probably.

I've found my comment on a filter that i created for NAV 2018:

//TempFile.SETFILTER(Filename, '@*%1*.pdf',DocumentNo); -> Isn't working as expected: %1 isn't replaced with the DocumentNo
TempFile.SetFilter(Filename, '@*' + DocumentNo + '*.pdf');
Arthurvdv commented 7 months ago

%1 isn't replaced with the DocumentNo

You're right, I have it backwards 🙈 It's not the operator that's becoming a literal character, but the placeholder (%1) isn't replaced.

I'll edit the issue on this, so it becomes more clear.

JMA1972 commented 7 months ago

As pri-kise explained this is standand platform behaviour. Almost every developer stumbles upon it at a time. Unfortunately changing it could be breaking code everybody relies on for decades even though the propability is high, that such code was written in ignorance of the problem.

Arthurvdv commented 7 months ago

Additionally I think that this is more a platform issue and less a compiler issue.

I experience this as a "AL Developer Experience Bug", so I though this was a good starting point here :-)
In case this is not the right place, I hope this issue could be transferred (or point me in the right direction).

Unfortunately changing it could be breaking code everybody

If breaking code is the concern, this could be handled with a feature flag on the Feature Management module.

kalberes commented 6 months ago

All true what was said above. It is by design. It is legacy. And it is documentation issue. Also a runtime. As far as I know the documentation update is opened for all. It should be updated with the correct behavior.