Building a "Generic" lookup function

rsaritzky
Member Posts: 469
I have a table that references multiple fields from other tables (similar to Config. Template, although Config. Template Line is limited to one “external” table.)
Each one of these fields has a “unique” lookup based on the table Relation on the field, or may be a Boolean (in which case the lookup should be Yes/No) or an Option field (in which case the lookup should be a list of the option values). I know how to devise the lookup for the Option and Boolean fields, but I want to build a "generic" lookup function for fields that have a TableRelation defined:
Here’s an example.
1. Field #10 “Eye Color” has a table relation of
"Attribute Field Values".Code WHERE (Table No.=CONST(50016),Field No.=CONST(19))
2. Field #11 “Hair Color” has a table relation of
"Attribute Field Values".Code WHERE (Table No.=CONST(50016),Field No.=CONST(18))
3. Field #12 “Education Level” has a table relation of
"Donor Attribute Field Values".Code WHERE (Table No.=CONST(50016),Field No.=CONST(50044))
Now, I am entering records in a separate table. I first enter the identifying information for the table/field:
- Source Table No (50016 in the above case)
- Field No. (10,11 or 12 in this example)
Now, I wish to do a Lookup for the “Field Value” of the selected field. So if I enter Field 10 (Eye Color), I want to display a lookup page on the “Attribute Field Values” table filtered by (Table No.=CONST(50016),Field No.=CONST(19))
If I enter field 11, then I want the same lookup page, but filtered by (Table No.=CONST(50016),Field No.=CONST(18))
Has anyone done a function like this? Perhaps look at the “TableRelation” through a FieldRef variable, then “parse” the TableRelation value to determine the filters?
Any ideas/examples would be appreciated.
Each one of these fields has a “unique” lookup based on the table Relation on the field, or may be a Boolean (in which case the lookup should be Yes/No) or an Option field (in which case the lookup should be a list of the option values). I know how to devise the lookup for the Option and Boolean fields, but I want to build a "generic" lookup function for fields that have a TableRelation defined:
Here’s an example.
1. Field #10 “Eye Color” has a table relation of
"Attribute Field Values".Code WHERE (Table No.=CONST(50016),Field No.=CONST(19))
2. Field #11 “Hair Color” has a table relation of
"Attribute Field Values".Code WHERE (Table No.=CONST(50016),Field No.=CONST(18))
3. Field #12 “Education Level” has a table relation of
"Donor Attribute Field Values".Code WHERE (Table No.=CONST(50016),Field No.=CONST(50044))
Now, I am entering records in a separate table. I first enter the identifying information for the table/field:
- Source Table No (50016 in the above case)
- Field No. (10,11 or 12 in this example)
Now, I wish to do a Lookup for the “Field Value” of the selected field. So if I enter Field 10 (Eye Color), I want to display a lookup page on the “Attribute Field Values” table filtered by (Table No.=CONST(50016),Field No.=CONST(19))
If I enter field 11, then I want the same lookup page, but filtered by (Table No.=CONST(50016),Field No.=CONST(18))
Has anyone done a function like this? Perhaps look at the “TableRelation” through a FieldRef variable, then “parse” the TableRelation value to determine the filters?
Any ideas/examples would be appreciated.
Ron
0
Answers
-
That is a rather challenging requirement for the general case.
You can find data you need to build the lookup in "Table Metadata" and "Table Relations Metadata" system tables.
Also have a look at the Codeunit "Page Management" to determine and call the lookup page.
I know of no way to call a lookup for a generic option field. I believe you will have to generate a temporary table containing the options. I am not sure if the required data is somewhere in a system table, but you can retrieve the necessary data from a FieldRef.
I have done something like it, but only in the much simpler case of the first code field in the primary key (for import/export code translations).0 -
You can do this with recordrefs, fieldrefs and a variant as parameter to the page.runmodal.
I once created this function to solve the same issue:
IF piLookupField = 0 THEN
piLookupField := 1;
lrrRecord.OPEN( piLookupTable);
IF pcodProposal <> '' THEN BEGIN
lfrField := lrrRecord.FIELD( piLookupField);
lfrField.SETFILTER( pcodProposal);
IF lrrRecord.FINDFIRST() THEN;
lrrRecord.RESET();
END;
lvarRecord := lrrRecord;
IF PAGE.RUNMODAL( 0, lvarRecord) = ACTION::LookupOK THEN BEGIN
lrrRecord := lvarRecord;
lfrField := lrrRecord.FIELD( piLookupField);
pcodSelectedValue := lfrField.VALUE;
EXIT( TRUE);
END;
EXIT( FALSE);
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