Creator Help

Form Actions - On Load

Overview

The On Load form action script is used to dynamically alter a form when it is loaded. The Form actions are executed when the form is loaded by a user to add a new record or when the form is loaded by a user to edit an existing record. For example, to set a date field in the form with the current date or to hide a field when the form is loaded.The script itself runs on the server side, immediately after the user's request is sent to the user's browser.

Syntax

On Add

The On Load script written in the Form Actions -> On Add -> On load block is invoked when the form is loaded to add a new record.  The Form definition of the script will be displayed in the Form Definition -> With Action block of the Script Builder, in the format given below.

actions
{
on add
{
on load
{
//write deluge script to be executed when a form is loaded to add a new record
.........................
}
}

}

On Edit

The On Load action script written in the Form Actions -> On Edit -> On Load block is invoked when the form is loaded to edit an existing record. The Form definition of the script will be displayed in the Form Definition -> With Action block of the Script Builder, in the format given below.

actions
{
on edit
{
on load
{
//write deluge script to be executed when a form is loaded to edit an existing record
..................
}
}
}

Steps to add the script

Refer the topic Using Script Builder for steps to add the script.

Examples

Some common scenarios when the On Load script is used, is given below:

  • Display current date in the date field when form is loaded on add
  • Hide fields while loading a form on edit
  • Set default values for fields on add
1. Display current date in the date field when form is loaded - on add

You can create a date field and set it with the current date, using the zoho.currentdate function. The following script added to Form Actions -> On Add -> On Load block will set the date field named "Sale_Date" with the current date, whenever the form is loaded.

Sale_Date = zoho.currentdate;

2. Hide fields while loading a form on edit

The following script added to Form Actions -> On Add -> On Load block, will hide the fields Name and EmailId in the form, and allow only the other field values to be edited by the applicant. The script will be executed when the user edits an existing record.

hide Name;
hide EmailId;

3. Set default value for fields on add

You can set default value for fields including picklist while loading a form. The following script added to Form Actions -> On Edit -> On load block will set the value "Available" to the form field "Status".

input.Status = "Available";

Top