Tech Tip: Utility Method to Get Tables' UUIDs
PRODUCT: 4D | VERSION: 15.1 | PLATFORM: Mac & Win
Published On: April 20, 2016
Below is a method to obtain the UUID of a Table in the 4D Database.
// Method: GetTableUUID // Parameters: // $1 - String Table Name // Output: // $0 - String Table's UUID // Method does not check if table actually exists //----------------------------------------------------------------------- C_TEXT($1;$tableName_t) C_TEXT($0) C_TEXT($struct_t;$xmlRef_t;$elemRef_t;$elemName_t;$value_t;$res_t) C_BOOLEAN($stop_b;$failed_b) EXPORT STRUCTURE($struct_t) $xmlRef_t:=DOM Parse XML variable($struct_t) DOM GET XML ELEMENT NAME($xmlRef_t;$elemName_t) $tableName_t:=$1 If ($elemName_t="base") $elemRef_t:=DOM Get first child XML element($xmlRef_t;$elemName_t) $stop_b:=False While ($stop_b=False) If ($elemName_t="table") DOM GET XML ATTRIBUTE BY NAME($elemRef_t;"name";$value_t) If ($value_t=$tableName_t) ON ERR CALL("err_method") DOM GET XML ATTRIBUTE BY NAME($elemRef_t;"uuid";$res_t) If (ok=0) $res_t:="false" Else $0:=$res_t End if ON ERR CALL("") $stop_b:=True End if End if If ($stop_b=False) $elemRef_t:=DOM Get next sibling XML element($elemRef_t;$elemName_t) If (OK=0) $stop_b:=True End if End if End while End if DOM CLOSE XML($xmlRef_t) |
Example
For the following tables:
Test Method:
C_TEXT($result1;$result2) $result1:=GetTableUUID ("Demo") $result2:=GetTableUUID ("TableA") |
Results: