KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method to GET the 'Map Null Values to Blank Values' state of a field
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: February 18, 2016

Below is a utility method that will return a boolean output based on whether field of interest has the "Map NULL values to blank values" property set.

// Method: IsFieldMappedNull
// Parameters:
// $1 - String Table Name
// $2 - String Field Name
// Output:
// $0 = True: "Map NULL values to blank values" property is set
// $0 = False: "Map NULL values to blank values" property is NOT set
// Method does not check if tables and fields actually exist
//-----------------------------------------------------------------------

C_TEXT($1;$table_t)
C_TEXT($2;$field_t)
C_BOOLEAN($0)
C_TEXT($struct_t;$xmlRef_t;$tableRef_t;$tableName_t)
C_TEXT($fieldRef_t;$fieldName_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;$tableName_t)
$table_t:=$1
$field_t:=$2

If ($tableName_t="base")
  $tableRef_t:=DOM Get first child XML element($xmlRef_t;$tableName_t)
  $stop_b:=False
  While ($stop_b=False)
    If ($tableName_t="table")
      DOM GET XML ATTRIBUTE BY NAME($tableRef_t;"name";$value_t)
      If ($value_t=$table_t)
        $fieldRef_t:=DOM Get first child XML element($tableRef_t;$fieldName_t)
        While ($stop_b=False)
          If ($fieldName_t="field")
            DOM GET XML ATTRIBUTE BY NAME($fieldRef_t;"name";$value_t)
            If ($value_t=$field_t)
              ON ERR CALL("err_method")
              DOM GET XML ATTRIBUTE BY NAME($fieldRef_t;"never_null";$res_t)
              If (ok=0)
                $res_t:="false"
              End if
              ON ERR CALL("")
              $stop_b:=True
            End if
          End if
          If ($stop_b=False)
            $fieldRef_t:=DOM Get next sibling XML element($fieldRef_t;$elemName_t)
            If (OK=0)
              $stop_b:=True
            End if
          End if
        End while
      End if
    End if
    If ($stop_b=False)
      $tableRef_t:=DOM Get next sibling XML element($tableRef_t;$tableName_t)
      If (OK=0)
        $stop_b:=True
      End if
    End if
  End while
End if

If ($res_t="true")
  $0:=True
Else
  $0:=False
End if


"err_method" is used for the ON ERR CALL is a blank method to escape the error encountered when attribute is not found due to the default being false.