I'm trying to allow my user to dynamic lookup ability based on which table ID (table object) they select in the previous form.
So the process would be create a record in
Table 1: No., Description and table id (object table #)
Table 2: Code, Name, etc
I want the system to dynamically look at table 1 (table id field) and allow the user to have a lookup in table 2 code field that references and returns the value specified by the table id field.
For example is the user sets customer (#18) in table 1, table 2 code field would lookup the customer No field.
Further more if the user sets item (#27) in table 1, table 2 code field would lookup the item No field.
and so on
It seems as if recordref should handle this???
Steve
0
Answers
To get dynamic lookup you would need to define a conditional relation on the code field to various tables, and the table ID field would serve as a condition filter. There should be as many conditions and as many relations as the number of tables which are supposed to be handled by your code. This is the standard way and the simplest way, it also allows you to specify in which field in the related table you are looking up the data.
If you are thinking about 'generic' solution handling all the tables, I'd like to point out that.
1) not every table has a LookupPageId property defined (LookupPageID is used to determine which page to open when PAGE.RUNMODAL(0.. ) is called
2) some of the tables have compound primary keys, and you have to specify somehow which field is going to be looked up
3) not all table has a code field in the PK, and those having may have a longer filed
4) PAGE.RUNMODAL does not open the page in lookup mode
5) not every table has a corresponding list page, which would be used in lookup
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
****I figured out a solution and will post code within a few days.
1. Add the page/table reference in Configuration Management
2. You have to use field ref (which is not included) to determine the first field in the table (assuming its the lookup value)
CLEAR(RecRef);
RecRef.OPEN(LookuptableId);
VarRef := RecRef;
IF PAGE.RUNMODAL(ConfigMgt.FindPage(LookuptableId),VarRef) = ACTION::LookupOK THEN
BEGIN
RecRef := VarRef;
MESSAGE('%1', RecRef.FIELD(IdentifyTheLookupField));
END;