ReservationEntry.SetFilter("Source Batch Name", '');In my event subscriber I then check if the Reservation Entry's filter on various fields are of specific values, however my condition on the "Source Batch Name" to check if the filter indeed is set to an empty string is always false.
SourceBatchNameFilter := ReservationEntry.GetFilter("Source Batch Name"); if SourceBatchNameFilter = '''' then //DoSomething...To my surprising this expression is always false even though the debugger is clearly showing me that the value of "SourceBatchName" = '''', I also tried to copy the value directly form the source of the variable with "copy value" and changed the condition to check for '' instead of '''' but to no avail.
if not (SourceBatchNameFilter <> '''') then //DoSomething...So how would I be able to check if an explicit empty filter string was set on a field when you only have the option to get the value out of the filter by calling .GetFilter?
SETFILTER("Source Batch Name",'%1',''). This is, however, tricky, as certain filter meta characters change the way values are folded into the filter string. In some cases, proper quoting applies, in other cases the same thing happens as if you used STRSUBST to create the filter string parameter, i.e.
SETFILTER(Field,STRSUBST('%1*','ABC'))and in even other cases what looks like a placeholder is treated as literal value.
''), you need to set the filter accordingly.
Answers
If you want to filter for a distinct value, you should always use SETRANGE. SETRANGE automatically quotes the value for you (or does behind the scenes what proper quoting would do).
If you can't, or don't want to use SETRANGE, you should use replacement placeholders. In your case this would be . This is, however, tricky, as certain filter meta characters change the way values are folded into the filter string. In some cases, proper quoting applies, in other cases the same thing happens as if you used STRSUBST to create the filter string parameter, i.e. and in even other cases what looks like a placeholder is treated as literal value.
So, in essence, GETFILTER returns '' because you SETFILTER ''. If you want to GETFILTER '''''''' (i.e. the filter expression ), you need to set the filter accordingly.
Check out the documentation on setting filter strings (ignore the section on the quick filter, unless you want to analyze how the system mangles your input by looking at the Filters section on the "About this page" page; take into account that you need to double all single quotes that are part of the filter string and surround the whole string with single quotes, in order to use it as a literal string in C/AL Code) and my analysis of how SETFILTER's parameters are treated.
I justed wanted to check for certain filters that are set on the reservation record, to then hook in with my event subscriber to trigger some code when certain filters are set.
So the literal string I compared the result of the GetFilter expression to wasn't escaped properly by me as you mentioned hence the to strings didnt match, thanks for the detailed overview of how the filters are applied by the SETRANGE/SETFILTER methods.