Dynamically SETFILTER

Marcel_B
Member Posts: 3
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
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
0
Comments
-
Marcel_B wrote:FirstPartGTxt := '''%1|%2|%3''';
SecondPartGTxt := ''',Variant1,Variant2';
MyDynamicFilterGTxt := FirstPartGTxt + ',' + SecondPartGTxt;
ItemGRec.SETFILTER("Variant Filter",MyDynamicFilterGTxt);MyDynamicFilterGTxt := MyDynamicFilterGTxt + '|' + NextPart;
or try to use STRSUBSTNO."Money is likewise the greatest chance and the greatest scourge of mankind."0 -
Dumb of me to forget about STRSUBSTNO. :oops:
Now it seems to work when I use this:
MyDynamicFilterGTxt := 'Variant1|Variant2';
ItemGRec.SETFILTER("Variant Filter",STRSUBSTNO('%1|%2','''''',MyDynamicFilterGTxt));
\:D/0 -
Marcel_B wrote:Dumb of me to forget about STRSUBSTNO. :oops:
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!kind of fell into this...0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions