KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method to Return Attributes of a Dataclass/Table
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: August 18, 2025

Below is a utility method that will return the attributes of Dataclass/Table in an object of collections for each "kind" of attribute:

// Method: Util_Get_Dataclass_Attributes
// Description: Returns an object of the dataclass attributes based on their "kind"
// If an invalid table is passed, a null object will be returned
//
// Parameters:
// - $table (Variant) : A table name, number, or pointer
// - $result (Object) : An object of collections for each "kind" of dataclass attributes
// "storage" > Standard field
// "relatedEntity" > ManyToOne Relation
// "relatedEntities" > OneToMany Relation
// "calculated" > Computed Attribute
// "alias" > atttribute built upon another attribute
// ------------------------------------------------------------------------------

#DECLARE($table : Variant)->$result : Object

ARRAY TEXT($arrProperties; 0)

var $tableName : Text
var $i : Integer

Case of
   : ((Value type($table)=Is longint) | (Value type($table)=Is real) | (Value type($table)=Is pointer))
      $tableName:=Table name($table)
   : ((Value type($table)=Is text))
      $tableName:=$table
   Else
      $tableName:=""
End case

If (ds[$tableName]#Null)
   OB GET PROPERTY NAMES(ds[$tableName]; $arrProps)
   $result:=New object("storage"; New collection; \
    "relatedEntity"; New collection; \
    "relatedEntities"; New collection; \
    "calculated"; New collection; \
    "alias"; New collection)
   For ($i; 1; Size of array($arrProps))
      $result[ds[$tableName][$arrProps{$i}].kind].push($arrProps{$i})
   End for
End if


The method can provide quick access to fields, to parse through an entity selection or check for any relations.

It can easily be used in any of the following ways, all cases will return the same results:
$tableNameText:="Table_1"
$res1:=Util_Get_Dataclass_Attributes($tableName)

$tableNumber:=1
$res2:=Util_Get_Dataclass_Attributes($tableName)

$tablePointer:=->[Table_1]
$res3:=Util_Get_Dataclass_Attributes($tableName)