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.
On Add: The on load script written in the On Add block is invoked when the form is loaded to add a new record.
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 On Edit block is invoked when the form is loaded to edit an existing record.
on edit
{
on load
{
//write deluge script to be executed when a form is loaded to edit an existing record
}
}
Examples - Free flow scripting
Some common scenarios when the on load script is used, is given below:
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 inside on load script. The following script will set the date field with the current date whenever the form is loaded.
form SampleForm1
{
Date1
(
type = date
)
on add
{
on load
{
set Date1 = zoho.currentdate;
}
}
}
|
2. Hide fields while loading a form on edit
The on load action script in the following example, will be executed when the user edits an existing record. The script will hide the fields Name and Email_id in the form, and allow only the other field values to be edited by the applicant.
form ApplicationForm
{
Name
(
type = text
)
EmailId
(
type = email
)
DateOfBirth
(
displayname = "Date Of Birth"
type = date
)
EducationalQualification
(
displayname = "Qualification"
type = picklist
values = {"Graduate", "PostGraduate", "Diploma", "Other"}
)
Experience
(
type = text
)
ContactAddress
(
displayname = "Contact Address"
type = textarea
)
ContactNumber
(
displayname = "Contact Number"
type = number
width = 20
)
BloodGroup
(
displayname = "Blood Group"
type = text
)
on edit
{
on load
{
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 will set the value "Available" to the form field "Status".
on add
{
on load
{
|
Example - Using Script Builder
Refer the topic, Client Side Function - Set Field - Example Using Script Builder.