Log In    |    Knowledge Base    |    4D Home
Tech Tip: Retrieving the field number based only on the field name
PRODUCT: 4D | VERSION: 2004.3 | PLATFORM: Mac & Win
Published On: February 24, 2006
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

If you only know the name of the field and you want to get the field number of it for reference, you can perform a similar code below.

`Method: GetFieldNumber
  `Description: This method returns the field number of a field. The name of the field is the one that is passed.
ARRAY TEXT(asFields;Count fields($tableNum))
For ($vlField;1;Size of array(asFields)) `Get all field names of table
  asFields{$vlField}:=Field name($tableNum;$vlField)
End for
$fieldNum:=Find in array(asFields;FieldName) ` Find field name in array
GET FIELD PROPERTIES($tableNum;$fieldNum;$fieldType)

The code below will use the method above to get the field number of the field "ID" and display it:
ALERT(String(GetFieldType(Table(->[Table 1]);"ID")))