Using temporary table to create lookup for a field

jorgito
Member Posts: 115
Hi all.
I have the following problem.
I have a field "Vendor No." in a table that is related to the Vendor table, but in the OnLookup trigger I want to restrict the displayed values.
So, I create a temporary table VendorsTemp (T23) and a form VendorList (F27).
I use the following code in the OnLookup trigger of the "Vendor No." field to fill the temporary table VendorsTemp.
The VendorsTemp table gets filled OK.
How do I display the VendorList form as Lookup and when the user clicks on a Vendor, the field "Vendor No." is filled in appropriately?
I tried some approaches, but I can't get it to work right.
Any suggestions?
Jorgito
I have the following problem.
I have a field "Vendor No." in a table that is related to the Vendor table, but in the OnLookup trigger I want to restrict the displayed values.
So, I create a temporary table VendorsTemp (T23) and a form VendorList (F27).
I use the following code in the OnLookup trigger of the "Vendor No." field to fill the temporary table VendorsTemp.
PurchRcptLineAssgmnt.SETRANGE("Document No.", "Document No."); PurchRcptLineAssgmnt.SETRANGE("Document Line No.", "Document Line No."); IF PurchRcptLineAssgmnt.FIND('-') THEN REPEAT IF Vendors.GET(PurchRcptLineAssgmnt."Vendor No.") THEN BEGIN VendorsTemp.INIT; VendorsTemp := Vendors; VendorsTemp.INSERT; END; UNTIL PurchRcptLineAssgmnt.NEXT = 0;
The VendorsTemp table gets filled OK.
How do I display the VendorList form as Lookup and when the user clicks on a Vendor, the field "Vendor No." is filled in appropriately?
I tried some approaches, but I can't get it to work right.
Any suggestions?
Jorgito
0
Comments
-
The easiest way to restric the vendor list is to set that restriction in the table relation property of the field itself. That way you don't have to program anything.0
-
In this case, you need the "How to do form based on temporary table".
http://www.mibuso.com/forum/viewtopic.php?t=9478
http://www.mibuso.com/forum/viewtopic.php?t=5180
etc.0 -
If you need to more complex conditions than a TABLE RELATION property can offer, you display a form like thish:
VendorList.lookupmode := true; VendorList.setrecord(VendorsTemp); if Vendorlist.RUNMODAL = ACTION::LookupOK then Vendorlist.GETRECORD(VendorsTemp);
Afterwards VendorsTemp contain the selected records.0 -
It is far too complicated to use the TableRelation propery.
I used the following codeVendorList.LOOKUPMODE := TRUE; VendorList.SETRECORD(VendorsTemp); IF VendorList.RUNMODAL = ACTION::LookupOK THEN BEGIN VendorList.GETRECORD(VendorsTemp); "No." := VendorsTemp."No."; END;
But I have 2 problems:
1. All the records from the Vendor table are displayed and not the ones in the VendorsTemp record.
2. When I double click on a vendor in the form, the original field does not change.
What am I doing wrong?
Jorgito0 -
SETRECORD for temporary table is not enough. Please, read the forum about the temporary tables and you can read for example "How to create report based on temporary table" - it is very similar.0
-
I have tried most of the solutions that are presented in this forum, but I couldn't find one for my problem.
I tried using the following codeIF FORM.RUNMODAL(0,VendorsTemp) = ACTION::LookupOK THEN BEGIN Rec."No." := VendorsTemp."No."; //MESSAGE(VendorsTemp."No."); END;
Now, the correct records are displayed in the lookup window, but when I click on OK, the value is not transferred in the original table.
If I use the MESSAGE function to find out the value that is returned, it is the correct one. But the original field is not updated with the value I clicked on in the lookup form.
Thank a lot
Jorgito0 -
Instead of:
Rec."No." := VendorsTemp."No.";
You should use:
Rec.GET(VendorsTemp."No.");
...
/Frank0 -
Finally, I found the solution to my problem.
I found in another topic that when you set the value of the field after the user has clicked on OK, you must useIF FORM.RUNMODAL(0,VendorsTemp) = ACTION::LookupOK THEN BEGIN VALIDATE("No.", VendorsTemp."No."); END;
instead ofIF FORM.RUNMODAL(0,VendorsTemp) = ACTION::LookupOK THEN BEGIN "No." := VendorsTemp."No."; END;
And if you are viewing the table from the Object Designer, the value is not transferred from the lookup table to the field.
Instead, if you run the FORM and try to use the lookup table, the field gets updated normally.
http://www.mibuso.com/forum/viewtopic.php?t=8143
Thanx everyone for your help
Jorgito0 -
I had what looked like a similar problem, I needed to get a list of Vendors based on The Purchase Header.Order Type (Option) and the Vendor.Status
The Table Relation works just fine:
IF (Order Type=CONST(" ")) Vendor ELSE IF (Order Type=CONST(Controlled)) Vendor WHERE (Status=FILTER(<>'')) ELSE IF (Order Type=CONST(Ancillary)) Vendor
This works also with using a FILTERGROUP in the Vendors List form:
UserSetup.GET(USERID);
FILTERGROUP(10);
IF UserSetup."Block Old Vendors" THEN
SETFILTER("No.", '<%1','X');
FILTERGROUP(0);
Bye the way, I wanted to use a filter like '<>%1', 'X*'
But that will not work, anyone know why?Experience is what you get when you hoped to get money0
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