SETFILTER and SETRANGE on one field

randrews
Member Posts: 135
Hi.
I need dynamicaly set several filter to one field.
I.e. sumary filter (values may be another)
myvar := 'VALUE1';
myvar := '';
myvar := 'VALUE2';
myvar := 'VALUE 3 BLANK';
SETRANGE(Field,myvar) - erase previous filter.
Doing
TextFilter += (myvar+'&');
SETFILTER(Field,TextFilter)
Then dificulty on checkin values with blank ''. Checkin if first value myvar<>'' (filter '&Value1&value2' wrong). Checking last value (then TextFilter += myvar, and not TextFilter += (myvar+'&');)
I can do it, but code is very bulky for that simple task.
May be somebody have a simple decision?
I need dynamicaly set several filter to one field.
I.e. sumary filter (values may be another)
myvar := 'VALUE1';
myvar := '';
myvar := 'VALUE2';
myvar := 'VALUE 3 BLANK';
SETRANGE(Field,myvar) - erase previous filter.
Doing
TextFilter += (myvar+'&');
SETFILTER(Field,TextFilter)
Then dificulty on checkin values with blank ''. Checkin if first value myvar<>'' (filter '&Value1&value2' wrong). Checking last value (then TextFilter += myvar, and not TextFilter += (myvar+'&');)
I can do it, but code is very bulky for that simple task.
May be somebody have a simple decision?
0
Comments
-
If you want a logical AND to combine your filters then you can use filter groups and set each filter in a different filter group.0
-
I think that there is no 'simple' solution. There is only 'complex' solution which must do all checks. In which way, it is on you... :-)
You can be inspired of code from Form 18 from function GetSelectionFilter which take all selected records and create the filter string for them. Automatically use .. or | based on selected records.
If you modify this code, you can use it for your need.
[Edited after posted]
Sorry... I forget that this code is not calculating with empty values.. ](*,) :-#0 -
Another solution:
Do checking of all empty values and replace them with string '%1'
Then do adding into one string...
useSETFILTER(Field,TextFilter,'')
It means that all %1 will be correctly replaced with empty string.
if the result is ''&VALUE2&VALUE3&'' is correct, ''&'' is equal to '' ('' is empty string) :-)
Have you fixed count of values or it is dynamic?0 -
First of all, i am mistaken
TextFilter += (myvar+'&'); \\wrong
TextFilter += (myvar+'|'); \\right
Count of values is dinamicaly changes.
Realy it deends on table SomeTable.
SomeTable.SETRANGE(Fild1,...)
SomeTable.SETRANGE(Fild2,...)
And all values SomeTable.Field3 is values for filtering second table.
REPEAT
TestFilter += SomeTable.Field3 +'|';
UNTIL SomeTable.NEXT =0;
SecondTable.SETFILTER(SomeField,TestFilter)0 -
randrews wrote:First of all, i am mistaken
TextFilter += (myvar+'&'); \\wrong
TextFilter += (myvar+'|'); \\right
Count of values is dinamicaly changes.
Realy it deends on table SomeTable.
SomeTable.SETRANGE(Fild1,...)
SomeTable.SETRANGE(Fild2,...)
And all values SomeTable.Field3 is values for filtering second table.
REPEAT
TestFilter += SomeTable.Field3 +'|';
UNTIL SomeTable.NEXT =0;
SecondTable.SETFILTER(SomeField,TestFilter)
my corrected code for you:TestFilter := ''; IF SomeTable.FIND('-') then begin REPEAT if SomeTable.Field3 = '' then TestFilter += '%1|' else TestFilter += SomeTable.Field3 +'|'; UNTIL SomeTable.NEXT =0 TestFilter := DELSTR(TestFilter,StrLen(TestFilter)); //for deleting last | end else TestFilter := 'somevalue if nothing to filter'; SecondTable.SETFILTER(SomeField,TestFilter,'');
another versionTestFilter := ''; IF SomeTable.FIND('-') then begin REPEAT if SomeTable.Field3 = '' then if TestFilter = '' then TestFilter := '%1'; else TestFilter += '|%1' else if TestFilter = '' then TestFilter := SomeTable.Field3 else TestFilter += '|' + SomeTable.Field3 ; UNTIL SomeTable.NEXT =0 end else TestFilter := 'somevalue if nothing to filter'; SecondTable.SETFILTER(SomeField,TestFilter,'');
and another one:TestFilter := ''; IF SomeTable.FIND('-') then begin REPEAT if SomeTable.Field3 = '' then FValue := '%1' else FValue := SomeTable.Field3; if TestFilter = '' then TestFilter := FValue else TestFilter += '|'+FValue; UNTIL SomeTable.NEXT =0 end else TestFilter := 'somevalue if nothing to filter'; SecondTable.SETFILTER(SomeField,TestFilter,'');
0 -
Thanks a lot, kine, for writing code. It is exactly what i needed
My code was more biger.
And thanks to all who helped and writed here0
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