Question about OnLookup Form

fabrizioc
Member Posts: 31
Hi to all, I'm very fresh as navision developer and I'm facing the following task.
In my Form I have a field called Item. No., and another field called Packing List No. that is a lookup field.
Each Packing List contains a list of Packing List Item and each Item is related to a specific Item No.
I'd like to prefilter the lookup field displaying only the Packing Lists containing the Item specified in Item No. field.
I'm trying to do the work in the OnLookup trigger of the Packing List No. field but without success, can someone suggest me a way to accomplish this task.
Thank you in advance for your help.
Fabrizio
In my Form I have a field called Item. No., and another field called Packing List No. that is a lookup field.
Each Packing List contains a list of Packing List Item and each Item is related to a specific Item No.
I'd like to prefilter the lookup field displaying only the Packing Lists containing the Item specified in Item No. field.
I'm trying to do the work in the OnLookup trigger of the Packing List No. field but without success, can someone suggest me a way to accomplish this task.
Thank you in advance for your help.
Fabrizio
0
Best Answer
-
You always reset your filter in your piece of code.
IF MyPackingListLine.FINDSET THEN BEGIN MyPackingList.SETFILTER("Packing List No.",MyPackingListLine."Packing List No."); END;
1st run: Filter = Item1
2nd run: Filter = Item2
This way when your loop is done the filter is set on the last item.
What you may want to try:CLEAR(MyPackingListLookupForm); MyPackingListLine.SETRANGE("Item No.","Item No."); IF MyPackingListLine.FINDSET THEN REPEAT MyPackingList.GET(MyPackingListLine."Packing List No."); //Or Setrange filtering depending on your key MyPackingList.MARK(TRUE); UNTIL MyPackingListLine.NEXT = 0; MyPackingList.MARKEDONLY(TRUE); IF NOT MyPackingList.ISEMPTY THEN BEGIN MyPackingListLookupForm.SETTABLEVIEW(MyPackingList); MyPackingListLookupForm.RUNMODAL; END;
Marking is used for kinda advanced filters that arent easily done with simply setfilter or setrange. Of course you could still build a filterstring (item1|item2|item3.....) but that's not how i would approach it.
More info: https://msdn.microsoft.com/en-us/library/dd355288(v=nav.90).aspxAustrian NAV/BC Dev5
Answers
-
HI,
Let us know what you tried.
Just a Tip - While Calling Lookup of the Table / Form, Pass A Record of Table with Filter of Item No.
Just wanted to make you think, if still any confusion let us know the code that you are trying.
Thanks & Regards,
Saurav Dhyani
Do you Know this About NAV?
Connect - Twitter | Facebook | Google + | YouTube
Follow - Blog | Facebook Page | Google + Page0 -
Dear postsaurav, thank you for your help, I've tried with a similar approach, here you can find the code of the OnLookup form trigger
CLEAR(MyPackingListLookupForm);
MyPackingListLine.SETFILTER("Item No.","Item No.");
IF MyPackingListLine.FINDSET THEN BEGIN
MyPackingList.SETFILTER("Packing List No.",MyPackingListLine."Packing List No.");
END;
IF MyPackingList.FINDSET THEN BEGIN
MyPackingListLookupForm.SETTABLEVIEW(MyPackingList);
MyPackingListLookupForm.RUNMODAL;
END;
WHERE
MyPackingListLookupForm is a variable of type Form Subtype Packing List - List
MyPackingList is a variable of type Record Subtype Packing List Header
MyPackingListLine is a variable of type Record Subtype Packing List Line
Item No is a field of the form
Now I'm able to retrieve the list of all PackingListLines with the Item. No. selected,
PackingListLines contains several Records I need to set the second FINDSET on MyPackingList with all the Packing List No. values retrieved in the step before.
Unfortunately only the last valus seems to be maintained by SetFilter.
Could you suggest me a way to perform this action ?
Thank you again for your precious help.
Best regards
Fabrizio
0 -
You always reset your filter in your piece of code.
IF MyPackingListLine.FINDSET THEN BEGIN MyPackingList.SETFILTER("Packing List No.",MyPackingListLine."Packing List No."); END;
1st run: Filter = Item1
2nd run: Filter = Item2
This way when your loop is done the filter is set on the last item.
What you may want to try:CLEAR(MyPackingListLookupForm); MyPackingListLine.SETRANGE("Item No.","Item No."); IF MyPackingListLine.FINDSET THEN REPEAT MyPackingList.GET(MyPackingListLine."Packing List No."); //Or Setrange filtering depending on your key MyPackingList.MARK(TRUE); UNTIL MyPackingListLine.NEXT = 0; MyPackingList.MARKEDONLY(TRUE); IF NOT MyPackingList.ISEMPTY THEN BEGIN MyPackingListLookupForm.SETTABLEVIEW(MyPackingList); MyPackingListLookupForm.RUNMODAL; END;
Marking is used for kinda advanced filters that arent easily done with simply setfilter or setrange. Of course you could still build a filterstring (item1|item2|item3.....) but that's not how i would approach it.
More info: https://msdn.microsoft.com/en-us/library/dd355288(v=nav.90).aspxAustrian NAV/BC Dev5 -
Thank you Wisa123 it's almost perfect, just a final but perhaps not mandatory request, is possible to UNMARK the selected records once the filter has been applied ? If yes, how ?
Thanks a lot for your help
Fabrizio0 -
MyPackingList.CLEARMARKS should do the trick (below tableview, before page.runmodal)
Regards, WisaAustrian NAV/BC Dev0 -
Thank you Wisa, I've tried but it seems not to work.....this is my current code:
IF NOT MyPackingList.ISEMPTY THEN BEGIN
MyPackingListLookupForm.SETTABLEVIEW(MyPackingList);
MyPackingList.CLEARMARKS;
MyPackingListLookupForm.RUNMODAL;
END;
Thank you again for your help.
Fabrizio0
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