Writing MetaScript for Database Fields and Variables

Writing MetaScript for Database Fields and Variables

MetaScript may be used on a form object basis as a method of calculating values of database fields and variables.

To create MetaScript for a database field or variable:

1. Select the field tool you want to use from the Tools Palette. MetaScript may be created for text entry fields, radio buttons, check boxes, and popups.
2. Move the pointer to the appropriate position, then click and drag to draw the field on the form. The Control Palette for the selected form is used to create the variable and specify other field options.
3. Click the Field expander button and select either the database field or Variable. If Variable is selected, type the variable name and select a datatype.
4. Click the MetaScript button in the Default/Calculate As field (if the variable option has been selected at the previous step, the Calculate As field replaces the Default field). Type the MetaScript code that will be executed beneath the variable or default value of the field element in the script editor window.

Scripts may include function definitions which may be called from other scripts within the form. For details on functions and commands supported by MetaScript, please refer to the MetaScript Reference manual.

Important! When specifying the default value for a form object, the type of the script's result must correspond to the type of the database field on which the form object is based. When calculating the value of a variable, the type of the script's result must be the one supported by the form object bound to this variable (for example, text entry fields can display string, integer, decimal, or date/time variables). Please, refer to the "Creating MetaScript for Dynamic Popups" section for more information on using MetaScript to dynamically populate popup fields with items.

TIP: While in the script editor window, you may use the Database Field button to quickly insert the name of any database field (except the file collector field) or variable placed on the form.

5. Specify the appropriate options for the form object. Attributes available are determined based on the Form Editor tool that was used to create the form object. Note, that form objects based on variables are non-editable and do not have the Allow Editing and Required editing properties.

Important! The Allow Editing option is used to calculate a database field value:
if the Allow Editing option is enabled, the script will be executed the first time the database record is added to the system using this form. This method is used to create the default value of the database field.
if Allow Editing is disabled, the script will be executed each time the database record is modified using this form. This method is used to provide automatic calculation of the database field value.
The scripts calculating values of the form variables will be executed each time the database record is modified using this form.

6. Apply the appropriate attributes (style, size, font, color) to the new variable field.
7. Select Save Form from the Form menu to save the changes you have made to the form.


Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.