I need to filter a list of items using C/AL Code.
I have a problem where the code errors when an item containing an equal sign is filtered. The same error occurs with bracketing.
For example part number ABC123(v2) would fail.
This occurs when manually applying a filter as well.
I have found that surrounding the string with quotes 'ABC123(v2)' fixes the issue when applying the filter manually.
How do I pass quotes into my variable?
Rec = Current Record: Item Table
SKU = Record Variable (Stockkeeping Unit Table)
Code
FilterNo := Rec."No.";
SKU.SETFILTER("Item No.", FilterNo);
End Code
I need my FilterNo variable to work like this:
SKU.SETFILTER("Item No.", 'ABC123(v2)');
Not
SKU.SETFILTER("Item No.", ABC123(v2));
Can someone please guide me in the right direction?
Thank you,
headley27
0
Comments
All ''' are three single quotes.
But how is this going to work if you have such special charecters in item no. ?? It will fail everywhere the item is used.
and
The first one apply 'something' as filter (plain filter), second one apply string 'something' like value you want to filter... Please, use first option just only if you have some filter saved in variable and you want to apply this filter. In other cases use the second option or use
if you are filtering for one value...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
That's exactly what I was looking for.
In the meantime, I had written some code to escape single quotes that existed in my variable. I then surrounded the variable with single quotes and passed it into the SetFilter function.
This worked for me using 7 lines of code but your solution gives me the same results using 1.
SKU.SETFILTER("Item No.",'%1',FilterNo);
Beautiful.
Thanks again,
headley27