KNOWLEDGE BASE
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

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.
C_TEXT($2;FieldName)
C_LONGINT($0;$1;$tableNum;$fieldType;$vlField)
$tableNum:=$1
FieldName:=$2
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)
$0:=$fieldNum


Example:
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")))