This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19
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. The value is extracted when the form is opened, but if it changes you can just call VP RECOMPUTE FORMULAS so that the 4D View Pro area uses the new value.

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

  • the field was declared as a formula using the VP SET CUSTOM FUNCTIONS command (see example).
  • 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.

Note: For security when the VP SET CUSTOM FUNCTIONS is not used (not recommended), only the fields belonging to the virtual structure of the database, i.e. declared through the SET TABLE TITLES and/or SET FIELD TITLES commands with the * parameter, can be called. In this case, table and field names must be ECMA compliant (see ECMA Script standard). 

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

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. In the form method of the form that contains the 4D View Pro area, you can write:
     Case of
        :(Form event code=On Load)
           var $o : Object
           $o:=New object
           $o.EMP_NAME:=New object //declare the function
           $o.EMP_NAME.formula:=Formula([Employee]L_Name)
           VP SET CUSTOM FUNCTIONS("ViewProArea";$o)
     End case
  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.

Note: When the VP SET CUSTOM FUNCTIONS command is not used (not recommended), fields declared in the virtual structure are entered with a syntax such as TABLENAME_FIELDNAME()



See also 

USE 4D FORMULAS IN YOUR SPREADSHEET (blog post)
VP SET CUSTOM FUNCTIONS

 
PROPERTIES 

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

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v17 R2

 
ARTICLE USAGE

4D View Pro Reference ( 4D v19)