Building a "Generic" lookup function

rsaritzkyrsaritzky Member Posts: 469
edited 2023-11-08 in NAV Three Tier
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.


Ron

Answers

  • vaprogvaprog Member Posts: 1,139
    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).
  • ACaignieACaignie Member Posts: 91
    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);

Sign In or Register to comment.