Hello everyone,
One of the departments in our company has requested a change that makes me need to be able to dynamically create a text variable that I can use as a filter, like this:
ItemGRec.SETFILTER("Variant Filter",MyDynamicFilterGTxt);
MyDynamicFilterGTxt needs to contain both the empty Variant Code, as well as a varrying number of filled Varinat Codes, which is why I was trying to build something along the lines of this:
ItemGRec.SETFILTER("Variant Filter",'%1|%2|%3','',VariantCode1,VariantCode2);
But since the filter will have to be set in various places all over the codeunit, I wanted to put the
'%1|%2|%3','',VariantCode1,VariantCode2 part in a text variable.
So I have been trying to accomplish that like this:
FirstPartGTxt := '''%1|%2|%3''';
SecondPartGTxt := ''',Variant1,Variant2';
MyDynamicFilterGTxt := FirstPartGTxt + ',' + SecondPartGTxt;
ItemGRec.SETFILTER("Variant Filter",MyDynamicFilterGTxt);
But then it tells me:
Filter ''%1|%2|%3','',Variant1,Variant2' is invalid.
I am working on a 3.70B version of Navision. Can anyone tell me if what I am trying to do is possible at all, and if so, what I am doing wrong, and how it should work?
Thanx a lot for your time and effort!

Marcel
Comments
Now it seems to work when I use this:
MyDynamicFilterGTxt := 'Variant1|Variant2';
ItemGRec.SETFILTER("Variant Filter",STRSUBSTNO('%1|%2','''''',MyDynamicFilterGTxt));
\:D/
thanks, this helped me tremendously today, but i went even further with a need to dynamically set the %1|%2|...|%X portion of the filter, and ended up using
table.SETFILTER(Field,STRSUBSTNO(FilterString,FilterStringValues))
I am not too concerned about string overflows at this time, which I saw others warning about in threads about dynamically building a filter. Thanks for tip!