4D v18

Field references

Home

 
4D v18
Field references

Field references  


 

4D View Pro allows you to use references to 4D database fields in your formulas. When displaying a 4D View Pro area, a field reference is replaced by the field value in the current record. A dynamic link is kept between the area and the 4D data: if the value of the field is changed, the 4D View Pro area will use the new value.

For security reasons, only fields and tables that have been included in the database "virtual structure" (i.e. renamed using SET TABLE TITLES and SET FIELD TITLES commands and the * parameter) can be called in 4D View Pro areas.

To be called in a 4D View Pro formula, a 4D field must comply to the following requirements:

  • the field belongs to the virtual structure of the database, i.e. it must be declared through the SET TABLE TITLES and/or SET FIELD TITLES commands with the * parameter (see example),
  • table and field names must be ECMA compliant (see ECMA Script standard),
  • the field type must be supported by 4D View Pro (see below).

An error is returned in the 4D View Pro cell if the formula calls a field which is not compliant.

4D View Pro supports references to fields of the following types:

TypeValue type in 4D View Pro
Alpha, Textstring
Integer, Long integer, Integer 64-bit, Real, Floatnumber
DateJavaScript Date type (hour, minute, sec = 0)
TimeJavaScript Date type (date in base date, i.e. 12/31/1899)
Booleanbool
Picturesupported picture types: jpg, png, gif, bmp, svg; other types converted into png. Creates an uri (data:image/png;base64,xxxx) set as background for the 4D View Pro cell where the formula is executed

To insert a reference to a field in a formula, enter the field with the following syntax:

TABLENAME_FIELDNAME()

For example, if you declared the "Name" field of the "People" table in the virtual structure, you can call the following functions:

=PEOPLE_NAME()
=LEN(PEOPLE_NAME())

Notes:

  • Only fields declared in the virtual structure of the database (using SET TABLE TITLES and/or SET FIELD TITLES) can be used in 4D View Pro formulas. Non declared fields will not be listed in the type-ahead list and calling an invalid field will result in a #NAME error displayed in the cell.
  • If a field has the same name as an allowed method, it takes priority over the method. 

Example  

We want to print the name of a person in a 4D View Pro area cell using a 4D field:

  1. Create an "Employee" table with a "L_Name" field:
  2. Execute the following code to initialize a virtual structure:
     ARRAY TEXT($tableTitles;1)
     ARRAY LONGINT($tableNum;1)
     $tableTitles{1}:="Emp"
     $tableNum{1}:=2
     SET TABLE TITLES($tableTitles;$tableNum;*)
     
     ARRAY TEXT($fieldTitles;1)
     ARRAY LONGINT($fieldNum;1)
     $fieldTitles{1}:="Name"
     $fieldNum{1}:=2 //last name
     SET FIELD TITLES([Employee];$fieldTitles;$fieldNum;*)
  3. Edit the content of a cell in the 4D View Pro area and enter "=e":
  4. Select EMP_NAME (use the Tab key) and enter the closing ).
  5. Validate the field to display the name of the current employee:

    Note: The [Employee] table must have a current record.

 
PROPERTIES 

Product: 4D
Theme: 4D View Pro Database References

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v17 R2

 
ARTICLE USAGE

4D View Pro Reference ( 4D v18)