Share via


Functions to Provide Initial Values for Form Fields

You can perform custom field initialization by defining a function that is used to provide the initial value for a field. To initialize a field using a function, you follow these steps:

  1. Define the function in a Form script. The function should return a value with the same type as the field, which is used to initialize the field.

  2. Associate the script with the form by ensuring that the check box for the script is checked in the list of scripts for the form.

  3. Create a new field or modify an existing field by selecting the Initial Value from the Field Properties form and then selecting Function from the drop-down list.

  4. Enter the function reference in the initialization data field. You can specify any parameters in the function reference that you could in a script.

When you create a new form, the field is initialized by executing the function.

Note that the initialization function is called when a form is initialized to create a new record. In contrast, the OnBeforeInitialize and OnAfterInitialize functions are called when a form is initialized for either a new or an existing record. The GetIsNew global function identifies when a script has been called for a new record.

If a field gets its initial value from a function and the function is not defined when the new record is created, the Forms tool will display a script error. If you include a field that is initialized by a function in more than one form, you must ensure that the script that defines the function is associated with each form that includes the field.

See Also

Concepts

Using Scripts in the Groove Forms Tool