Multiple conditions to a field filter
slmaluwa
Member Posts: 366
hi
I am trying to find a way to add multiple filters programmatically. Example. i filter the Location table to select more than one locations and i want to apply all these locations to ITEM table location filter table.
I tried the following and it didn't work.
It displays only the last Location code.
Is there a way to do it?
I am trying to find a way to add multiple filters programmatically. Example. i filter the Location table to select more than one locations and i want to apply all these locations to ITEM table location filter table.
I tried the following and it didn't work.
Location.RESET;
Location.SETRANGE("A Field To Select",true);
if Location.find('-') THEN begin
item.reset;
REPEAT
item.SETRANGE("lOCATION FILTER",Location.CODE);
UNTIL Location.NEXT=0;
end;
MESSAGE(ITEM.GETFILTERS());
It displays only the last Location code.
Is there a way to do it?
"A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."
0
Comments
-
I would do the following:
Declare a txtLocFilter of Text 250.
Then do this:
IF Location.FIND('-') THEN REPEAT
IF txtLocFilter = '' THEN
txtLocFilter := Location.Code ELSE
txtLocFilter := txtLocFilter + '|' + Location.Code;
UNTIL Location.NEXT = 0;
item.SETFILTER("Location Filter",txtLocFilter);
But test it because I think that you'll get a runtime error if your text becomes too large.
You could improve this code by checking for continuous location in order to create a more complex string that will contain something like this:
Loc1..Loc6|Loc9|Loc10..Loc19
Hope it helps...0 -
What do you want to do with the "Location Filter" on Item.
If you explain that, maybe we can find a better way to solve your problem.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
kriki wrote:What do you want to do with the "Location Filter" on Item.
If you explain that, maybe we can find a better way to solve your problem.
What do you want to do with the "Location Filter" on Item.
If you explain that, maybe we can find a better way to solve your problem.
exactly, because the code you wrote (slmaluwa) is totally crazy... :-k
every loop you do in repeat-until structure, overwrites the previous filter...
0 -
Hello
Sorry, I missed to see the last two replies.
What I wanted to do is simple requirement of getting the (sum) total inventory available in all those selected location.
I thought setting up this filter and doing a CALCFIELDS(Inventory) and display the qty on the form.
I thought it will be faster than looping through each location to set individual filter and do the calcfields
I am all ears for learning"A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."0 -
In case you have lots of locations, and only a few locations you need, it is better to loop the locations.
The reason is that OR-ing can make SQL decide to read all records in the SIFT.
If you need to run that code a lot, it is also a good idea to have the locations you need in a temptable on the form to avoid requesting all the time those locations.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Sorry, bit confused. How exactly the LOOP to be constructed?kriki wrote:In case you have lots of locations, and only a few locations you need, it is better to loop the locations.
The reason is that OR-ing can make SQL decide to read all records in the SIFT.
Is it the Location table to be made temp in that form? Out location table has around 18 locations.kriki wrote:If you need to run that code a lot, it is also a good idea to have the locations you need in a temptable on the form to avoid requesting all the time those locations."A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."0 -
OnInit: This is to fill up the temptable when the form is initialized
recLocation.RESET; recLocation.SETCURRENTKEY(...); recLocation.SETRANGE("A Field To Select",TRUE); IF recLocation.FINDSET THEN REPEAT tmpLocation := recLocation; tmpLocation.INSERT(FALSE); UNTIL recLocation.NEXT = 0;
This function, you can call where you want. You can also create a field on the item card and put this function in the SourceExpression.
(BTW : you can also call this function from another object. The OnInit of this form makes sure the temptable is loaded in the form-variable)Function CalculateInventory(IcodItemNo : CODE20) : OdecInventory : DECIMAL BEGIN OdecInventory := 0; tmpLocation.RESET; IF tmpLocation.FINDSET THEN REPEAT CLEAR(LrecItem); // "LrecItem" is a local record-variable on table Item LrecItem."No." := IcodItemNo; LrecItem.SETRANGE("Location Filter",tmpLocation.Code); Lrecitem.CALCFIELDS(Inventory); OdecInventory += Lrecitem.Inventory; UNTIL tmpLocation.NEXT = 0; END;Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!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
- 322 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