Referencing dynamic tables and fields
You may, on occasion, need to retrieve data from the system, but not know in advance where that data should come from. NAV accommodates this by allowing you to reference tables and fields dynamically.
How to do it...
Create a new codeunit from Object Designer.
Add a global function,
GetFirstRecord
.The function should take in the following parameter:
Name
Type
TableNo
Integer
Add the following local variables:
Name
Type
RecRef
RecordRef
FieldRef
FieldRef
Write the following code in your
GetFirstRecord
function:RecRef.OPEN(TableNo); IF RecRef.FINDFIRST THEN BEGIN IF RecRef.FIELDEXIST(1) THEN FieldRef[1] := RecRef.FIELDINDEX(1); IF RecRef.FIELDEXIST(2) THEN FieldRef[2] := RecRef.FIELDINDEX(2); IF FieldRef[1].ACTIVE AND FieldRef[2].ACTIVE THEN MESSAGE('Table: %1\%2: %3\%4: %5', RecRef.NAME, FieldRef[1].NAME, FieldRef[1].VALUE, FieldRef[2].NAME, FieldRef[2].VALUE) ELSE MESSAGE('You cannot retrieve an inactive field.'); END ELSE MESSAGE('No records...