Dynamic Field Names using different databases

Hi all,

I need to add to my XMLPort solution for an interface some logic to allow check the existence of a field before I try to bring the data to the XML content.

Then I have several databases where the Value Entry table can have or not the field SALESPERSON, so depending on wich database I’m running on I need to know if the field exists previous to use it on the rest of the logic.

How can I get that information without getting an error on compile because the field does not exist?

I think something as:

xVarName := ‘FIELDX’;

nVarPos := FIELDNO( xVarName );

If nVarPos > 0 THEN

myVar := table.FIELD( nVarPos )

Else

myVar := ‘NOT FOUND’;

I tried several things I’ve found on other posts and forums, like:

Lookup(Field.FieldName WHERE (TableNo=CONST(27),No.=FIELD(FieldID Filter)))

or

CASE varFieldname Of
Rec.FIELDNAME(FieldName1):
Rec.SETCURRENTKEY(Fieldset1);
Rec.FIELDNAME(FieldName2):
Rec.SETCURRENTKEY(Fieldset2);
END;

I thank so much if somebody can givme a sample on how to do this on NAV

I’m running NAV 5.0 SP1

Regards

Use a RecordRef and the FieldExists function.

Exist := RecordRef.FIELDEXIST(FieldNo)

Hi Matt,

Thanks for your answer…

I still have a problem, I don’t have the FieldNo to pass as parameter, I just have the field name I’m looking for, also the FieldNo can be different between databases.

Is there a way to get the FieldNo based on the name?

Thanks again

Try Field Table and Put filter on Table No. and Fiend Name…You can No. from there…

Hi Mohana,

It worked… my work is done.

Thanks a lot!! [:)]

Welcome [:)]

Hi Mohana,

what is this field table.

Is there any table which contain all fields of tables in Dynamics NAV???

yes…

The Field virtual table contains information about fields in database tables