Professional Documents
Culture Documents
Table of Contents
OVERVIEW................................................................................................................ 3
Why scripting in Zoho Creator? ........................................................................................... 4
Should I have programming experience to code in Deluge? ............................................... 5
Getting Started with Scripting .............................................................................................. 6
Script Builder ....................................................................................................................... 8
FORM ACTIONS...................................................................................................... 12
Form Actions - On Load..................................................................................................... 13
Form Actions - Validate ..................................................................................................... 17
Form Actions - On Success ............................................................................................... 22
FIELD ACTIONS...................................................................................................... 25
Field Actions - On User Input............................................................................................. 26
Field Actions - On update .................................................................................................. 28
FILTERS .................................................................................................................. 34
Criteria in Import Picklist Data ........................................................................................... 39
Formula.............................................................................................................................. 41
STATEMENTS ......................................................................................................... 43
Conditional Execution - If, else if, else........................................................................................... 45
Iterators .......................................................................................................................................... 48
Iterate Form Rows (for each record)........................................................................................ 48
Iterate Multiple Picklist Values (for each list value).................................................................. 50
Cancel submit ................................................................................................................................ 62
Set Variable ................................................................................................................................... 68
Data Access....................................................................................................................... 71
Fetch Records................................................................................................................................ 72
Modify Records .............................................................................................................................. 75
Client Side Functions......................................................................................................... 86
Client Side Function - Hide and Show ........................................................................................... 87
Client Side Function - Set Field ..................................................................................................... 90
Client Side Function - Add to Picklist Dynamically ........................................................................ 95
Client Side Function - Clear Picklist............................................................................................... 96
Client Side Function - Alert Box................................................................................................... 110
Miscellaneous .................................................................................................................. 111
Sending Mail ................................................................................................................................ 112
Success Message........................................................................................................................ 113
Add Comment .............................................................................................................................. 121
AdventNet, Inc. 1
Help Document Deluge Script
AdventNet, Inc. 2
Help Document Deluge Script
Overview
Deluge Script is an online scripting language integrated with Zoho Creator. Deluge Script
enables users to incrementally add logics to the application and make it more powerful
and robust.
To mention a few powerful applications you can create using Deluge Script -Library
Manager, Recruitment application, Inventory Management...
Unique features of Deluge Script:
• User-friendly Syntax - The Deluge Script syntax is easy to read and
understand. So the process of creating powerful application is fun, easy and
quick.
• Code is Data - Deluge Script has no concrete syntax. The syntax you see is just
a "skin". The actual code is stored as abstract syntax (i.e a whole bunch of
tables) in the database. So in future users will be able to generate the same code
in their own favourable syntax. For eg: Sam can edit the code in the standard
Deluge syntax while Lucy can edit the same code in a her favourable Perl syntax.
• Relational Data Model - Applications built by users have a fully normalized
relational data model.
• Query Integrated Language - Deluge Script bridges the gap between the
program logic written in a high level programming language and the data that it
operates upon. It brings the expressiveness of SQL closer to the core application
logic. i.e. query is integrated at the language level.
AdventNet, Inc. 3
Help Document Deluge Script
Zoho Creator helps you to easily create personal and business web applications on your
own by structuring and presenting your data in a lot of interesting and useful ways. You
can view the data as a table, calendar or just as a summary. In addition to just viewing
your data in many ways, you might also want to perform one or more of the following:
• Modify the form contents dynamically when it is loaded, both while adding/editing
a row. Learn more
• Validate form data before persisting it. For example, in a recruitment application,
accept only those applicants who have more than two years of experience. Learn
more
• Perform an action after a form data is persisted, both while adding/editing a row.
For example, you might want to receive email notifications as and when a row is
added. Learn more
• Modify the form contents dynamically whenever the value of a field in the form is
changed. For example, in a Bug Tracker application, display only those team
members who belong to the module chosen in the Module picklist field. Learn
more
• Perform an action only when the value of a field is modified and persisted in the
database. For example, in the case of a bug tracker, you might want to receive
email notifications whenever the status of the issue gets modified. Learn more
• Define formula fields for calculations. For example, assume a student database
has marks obtained by students in all the subjects and you want to display the
total and average marks also. Learn more
• Create complex filters in views. Learn more
With Zoho Creator, you don't have to write code to build a simple data
collection and viewing application like a Contacts list. But, scripting will be
indispensable for building a full fledged application with complex logic, for
example, Library Manager.
AdventNet, Inc. 4
Help Document Deluge Script
Zoho Creator/Deluge primarily addresses the needs of a large number of people who
have a requirement for a web application but do not know to build it on their own. You
need not be aware of Java, JSP, PHP, JavaScript, HTML or CSS. You just need to have a
clear idea about the application you want to build and how you want it to be presented.
The deluge script builder will take care of converting your logic into easy and natural
deluge script.
Though the applications created using zoho creator are database driven, you need not
know the relational database principles. The entire database layer is abstracted and you
will only speak in terms of forms and fields while scripting in Deluge. A HR manager who
wants to create a recruitment application, a home maker who wants to keep track of her
monthly expenses, a sales guy who wants to keep track of his leads can all code very
easily using Deluge. And a techie who slogs all day creating a web app using
conventional tools would be just amazed at how fast it is to do the same using Deluge.
AdventNet, Inc. 5
Help Document Deluge Script
You can create an entire application by writing Deluge Script or create your application in
Zoho Creator GUI and add form and field actions by writing Deluge Scripts.
Refer the topic "Creating a New Application -> Deluge Script" in Zoho
Creator Help Document, for more information.
When your form is created, you can add action scripts to your form or individual form
fields using the Script Builder. The script builder can be invoked either from the Forms
Tab or from the Script Tab.
• To add action script whenever you update the value of a field in the
form,
o Select the form and move the mouse over the required field
in the form.
o Select Actions on Field Change. This will invoke the Script
Builder in the Script tab
AdventNet, Inc. 6
Help Document Deluge Script
Selecting the Script Tab directly will invoke the Script Builder with the
Form actions and Field actions displayed on the left-side tree.
Refer Script Builder for more information on using Script Builder to add
scripts.
AdventNet, Inc. 7
Help Document Deluge Script
Script Builder
• Overview
• User Interface
• Using Script Builder
• Example
Overview
The Deluge Script Builder provides a drag-and-drop user interface for adding action
scripts to your application. It enables you to transfer complex application logic into
deluge code, without the need to learn or remember the Deluge syntax and functions. It
helps in creating Deluge action scripts quickly, without any errors.
User Interface
To use script builder, select the Script tab. The user interface of the script builder
comprises of the following as highlighted in the screen-shot below:
1. The Select list box numbered 1, displays the form names and view names in the
application.
2. The Form Actions navigation box numbered 2, displays the actions configured for
the selected form.
3. The Field Actions navigation box numbered 3, displays the fields that are present
in the selected form and the actions configured for the fields.
4. The Form Definition navigation box numbered 4, displays the field definitions for
the selected form.
5. The left-side tree of the script builder numbered 5, displays the tasks/statements
supported in deluge.
6. The area numbered 6 is the editor area where you can drag and drop the deluge
task/statements to build a complete script. A sample validate action script will be
displayed, by default.
7. The area numbered 7 highlights the modes available for viewing the script. By
default, the script builder tab is selected. To add scripts without using script
builder, you can select the Free-flow Scripting tab.
AdventNet, Inc. 8
Help Document Deluge Script
The basic steps involved in creating a script using the script builder is given below:
The forms and views created for the application will be listed in the select
box at the top left corner. Select the required form for which the action
script needs to be added.
The left-side tree of the script builder displays the tasks/statements that
can be used to perform form and field actions.
1. Drag the required task and drop it in the editor area, to display its
syntax. In the screen-shot given below, the If statement is selected
and dropped in the editor area. The syntax of the If statement is
displayed in the editor area.
2. Select the Edit option to add the required condition to the If
statement. To delete the syntax, select Delete.
AdventNet, Inc. 9
Help Document Deluge Script
3. Select the Edit option. This will display the dialog as shown in the
screen shot given below.
a. The tabs in this dialog named a, will enable you to
create the required condition. Each tab is explained
below.
AdventNet, Inc. 10
Help Document Deluge Script
Examples
Examples on adding scripts using script builder is covered for each deluge task
seperately. For example, to add the If Statement in Script builder, refer the topic,
Statements -> Control Statements -> If, else if, else.
AdventNet, Inc. 11
Help Document Deluge Script
Form Actions
Zoho creator supports to perform form actions by executing deluge scripts when a new
record is added or when an existing record is modified. The form actions supported by
Zoho Creator is given below:
• On Load
• Validate
• On Success
AdventNet, Inc. 12
Help Document Deluge Script
• Description
• Syntax
• Example - Free Flow Scripting
• Example - Using Script Builder
Description
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 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
}
}
AdventNet, Inc. 13
Help Document Deluge Script
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 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;
}
}
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
AdventNet, Inc. 14
Help Document Deluge Script
(
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;
}
}
AdventNet, Inc. 15
Help Document Deluge Script
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
{
set Status = "Available";
}
Refer the topic, Client Side Function - Set Field - Example Using Script Builder.
AdventNet, Inc. 16
Help Document Deluge Script
• Description
• Syntax
• Example - Free Flow Scripting
• Example - Using Script Builder
• Related Links
Description
An application that gives a free ride to input incorrect data is useless. By default, Zoho
Creator supports validation for an adequate number of field types. You can specify the
constraints for the fields you are defining while creating a form. For example, if you
define a field to be of type Email, Zoho Creator checks if the data entered in the form for
that field is a valid emailid, else it will display an error message to the user.
In addition to the default validation, Zoho creator allows you to write action scripts for
custom validation which is called when a user submits the form to the server, before the
user data is stored in the database. The script runs on the server side, and it has access
to all the inputs the user entered. The syntax for the user input is
input.<variable_name> as the examples below indicate.
The default action of validate is to submit the data, so you have to do a cancel submit
if you want to stop a form from being submitted. You can also choose to provide proper
alert message to the user while cancelling. The same form is then shown to the user to
re-enter the data.
The Validate action scripts are executed when a new form data is submitted or when an
existing record is modified and submitted.
Note:
• The validate action in the On Add block gets executed when a new
form data is submitted.
• The validate action in the On Edit block gets executed when an
existing record is modified and submitted.
• The data gets persisted only if the form does not get cancelled.
Syntax
Validate form action - On Add : The validate form action script written
in the On Add block is executed when when a new form data is submitted.
AdventNet, Inc. 17
Help Document Deluge Script
on add
{
on validate
{
// write validate form action to be executed when
a new form data is submitted
{
// specify alert message if not valid and
cancel submission
alert "<Specify alert message>";
cancel submit;
}
}
}
Validate form action - On Edit : The validate form action script in the
On Edit block is executed when an existing record is modified and
submitted.
on edit
{
on validate
{
// write validate form action to be executed when
an existing record is modified and submitted
{
// specify alert message if not valid and
cancel submission
alert "Enter valid Date of Birth";
cancel submit;
}
}
}
In the following sample, if the value specified in the age field is less than 20 or
greater than 100, the submit action will get cancelled.
AdventNet, Inc. 18
Help Document Deluge Script
on add
{
on validate
{
if (input.DateOfBirth.getYear() >
zoho.currentdate.getYear())
{
alert "Enter valid Date of Birth";
cancel submit;
}
}
}
on edit
{
on validate
{
if (input.DateOfBirth.getYear() >
zoho.currentdate.getYear())
{
alert "Enter valid Date of Birth";
cancel submit;
}
}
}
In the below example, if the same team member is added more than once, the
submit action will get cancelled.
on add
{
on validate
{
if (count(team_member[name == input.name]) >
0)
{
alert "Name already exists";
cancel submit;
}
}
}
where,
AdventNet, Inc. 19
Help Document Deluge Script
The following deluge code, checks for the required condition for
cancelling submission. Here, the count function is used to count
the number of records in a database. If the condition is satisfied,
displays an alert message to the user and cancels the submission
so that the record is not stored in database.
on add
{
on validate
{
if(count(Employee)>= 20)
{
alert("No more registrations allowed");
cancel submit;
}
}
}
on add
{
on validate
{
if (zoho.currentdate > '20-Mar-2007')
{
alert "time for registration expired";
cancel submit;
}
}
}
In the following deluge code, the value of the field PatientID is calculated based
on the form values specified for the First_Name and Last_Name and the value
returned by the variable zoho.currenttime.
on add
{
on validate
{
input.PatientID = input.First_Name + " " +
input.Last_Name + " " + zoho.currenttime;
}
}
AdventNet, Inc. 20
Help Document Deluge Script
on edit
{
on validate
{
input.PatientID = input.First_Name + " " +
input.Last_Name + " " + zoho.currenttime;
}
}
Refer the example in the topic, Statements -> Control Statements -> Cancel Submit.
Related Links:
AdventNet, Inc. 21
Help Document Deluge Script
Description
To perform any action after after the data is submitted and stored in the database., e.g
send a mail as soon as a feedback form is submitted, you need to write the on success
script for a form. The on success action scripts are executed after the data is stored in
the database. The user supplied data is already in the database when this script is run.
Syntax
on add
{
on success
{
// write deluge script to be executed when a new
form data is persisted in the database
}
}
on edit
{
on success
{
//write deluge script to be executed when a new
form data is persisted in the database
}
}
AdventNet, Inc. 22
Help Document Deluge Script
Send Mail : In the below given feedback form sample, a mail is sent when a new
form data is persisted in the database.
sender
(
displayname = "From"
type = email
)
mail_subject
(
displayname = "Subject"
type = text
)
category
(
displayname = "Category"
type = radiobuttons
values = {General, Usability, Bug
Report, Feature Request}
)
comments
(
displayname = "Comments"
type = textarea
)
status
(
displayname = "Status"
type = picklist
values = {Open, Closed, In progress}
private = true
)
on add
{
on success
{
sendmail
(
To : input.sender
Subject : input.mail_subject
Message :
input category+"<br>"+input comments
AdventNet, Inc. 23
Help Document Deluge Script
)
success message "email sent";
}
}
list "Send_Feedback_view"
{
show all rows from Send_Feedback
(
sender
mail_subject
category
comments
)
filters
(
category
)
}
}
}
Code Description
In the above code, the sendmail function is added in the on success form action,
where
input.<fieldname> - replaces the value specified in the form for the fieldname to
the To:, Subject:, and Message: entries.
Related Links
AdventNet, Inc. 24
Help Document Deluge Script
Field Actions
Zoho creator allows you to write deluge action scripts when ever the value of a field gets
modified or is changed in the form. These action events are field specific and these
scripts will be invoked only when a particular field value changes. The following field
action scripts are supported:
AdventNet, Inc. 25
Help Document Deluge Script
• Description
• Syntax
• Examples - Free flow scripting
• Examples - Using Script Editor
Description
On User input is a client side action, which will be invoked whenever you change the
value of a field in the form. It is used to improve the usability of a form by validating
field data even before it is submitted or modify field values based on user action (on
other fields).
Syntax
On User Input
{
// specify deluge code to be executed
Examples
Example 1:
Assume that in a form with Emailid field, a person can register with the same
Email ID only once. This validation can be done in the On User Input event of
the Email ID field. An Ajax request is sent to the server to validate the Email ID.
If the same emailid already exists, an error message is displayed.
AdventNet, Inc. 26
Help Document Deluge Script
On User Input
{
if (count(Register[emailid == input.emailid]) > 0)
{
set emailiderror = “This email id already exists”;
show emailiderror;
}
}
Example 2:
Assume a Bug Tracker application that has a form for filing issues as shown
below. The Module picklist field will display the name of all the modules. If a
module is selected from the list, only those members of the team, in charge of
the that module should get listed in the ‘Assigned to’ picklist. This can be done by
writing an ‘On User Input’ event for the ‘Module’ picklist.
Refer the Example - Free Flow Scripting in the topic, Client Side Functions ->
Clear Picklist.
Refer the Example - Using Script Builder in the topic,Client Side Functions
-> Clear Picklist.
AdventNet, Inc. 27
Help Document Deluge Script
• Description
• Syntax
• Example - Free Flow Scripting
• Example - Using Script Builder
Description
If you want to perform action whenever the value of a field gets modified, you can write
an on update script for that field. The on update action gets executed after the changed
data is persisted in the database.
Note:
Syntax
on update
{
// specify deluge code to be executed
Let us take the example of a Feedback Application form. In the below sample,
whenever the status of a feedback is changed to Closed, a mail will be sent to the
person who had reported it.
form Feedback_Form
{
displayname = "Feedback Form"
Your_Email_Address
(
displayname = "Your Email Address"
type = email
)
Feedback_Category
(
displayname = "Feedback Category"
type = picklist
AdventNet, Inc. 28
Help Document Deluge Script
Comments
(
type = textarea
on update
{
if (input.Status == "Closed")
{
sendmail
(
To : input.Your_Email_Address
Subject : "The feedback you had sent has
been incorporated in zohocreator"
Message : "The details are as below" +
"Category " + input.Feedback_Category
+ "" + "Comments " + input.Comments
)
}
}
)
Status
(
type = picklist
values = {"Open", "In-Progress", "Closed"}
)
on add
{
on success
{
sendmail
(
To : input.Your_Email_Address
Subject : "Your request has been registered
with us"
Message : input.Feedback_Category +
input.Comments
)
success message "Email sent to" + " " +
input.Your_Email_Address;
}
}
}
}
Let us add the deluge code for the above example, using script builder. In the Feed
Application form, if the value of the field status is updated to "Closed", the sendmail
function is called, to send a mail to the sender.
• Add On Update action
o If <condition>
o sendmail
AdventNet, Inc. 29
Help Document Deluge Script
1. Add On Update field action: To add an action when the status field in
Send_Feedback form is changed,
a. Select the form Send_Feedback from the list of forms displayed in the
top left corner of the script editor.
b. Select Field Actions -> status -> On Update, as shown in the screen-
shot below.
2. Add If <condition>
c. The Edit dialog for If is displayed as shown below, wherein you have to
create the If condition.
• Click on the Status field from the list of Input fields. The text
input.status will be added to the text area as highlighted below.
• Select the == operator and specify the value of the status field as
"Closed".
• Click Done to add the If condition to the script editor.
AdventNet, Inc. 30
Help Document Deluge Script
AdventNet, Inc. 31
Help Document Deluge Script
b. The Edit dialog displays the default values. To modify the default
values, click on the icon on the right-side of each field and specify the
required values. Click on Done to add the script to the script editor.
AdventNet, Inc. 32
Help Document Deluge Script
d. To view the complete script, select Form Definition -> With Action or
select Free-flow Scripting. The on update script is successfully added to
the form definition, as shown below.
AdventNet, Inc. 33
Help Document Deluge Script
Filters
AdventNet, Inc. 34
Help Document Deluge Script
• Creating Views
• Base Criteria
• Auto Filters
• Custom Filters
Creating Views
By default, all the entries in a form will be displayed in the view. Filters are a set of
named criteria that allows you to select only specific entries in a view. Default filters will
be created for single-select and multi-select fields. The Deluge syntax to display all the
rows in a form with default filters, is given below.
Syntax
)
filters
(
< Single select/Multiple select Field name >
< Single select/Multiple select Field name >
)
}
Base criteria
While getting a book from the library, you will definitely like to first look at the books list
that has not been issued to anybody. This is a often required feature. This can be easily
achieved by setting matching criteria while creating views. To specify the base criteria in
script mode, add the required criteria as highlighted in the code below.
list "ApplicationForm_View"
{
show all rows from ApplicationForm
[EducationalQualification == "Diploma"]
AdventNet, Inc. 35
Help Document Deluge Script
Name
DateOfBirth as "Date Of Birth"
EmailId
Experience
ContactAddress as "Contact Address"
ContactNumber as "Contact Number"
BloodGroup as "Blood Group"
EducationalQualification as "Educational Qualification"
)
filters
(
EducationalQualification
Experience
BloodGroup
)
}
In the above code, only those records in the ApplicationForm whose Educational
Qualification is Diploma can be viewed by the user, as shown in the screen shot below. If
the base criteria is not specified, all the records can be viewed by the user.
Auto Filter
Zoho creator creates default filters for the fields belonging to any of the following types.
These filters are called "Auto filters".
It is enough to just specify the name of the field as the filter, as specified in the sample
code below. For example:
filters
(
Qualification
Experience
Blood Group
)
AdventNet, Inc. 36
Help Document Deluge Script
In the Zoho Creator GUI mode, the default filters will be displayed. You can
enable/disable the auto filters by selecting/deselecting the show checkbox. By default, it
is disabled.
Name of the field will be taken as the name of the filter. The values for the fields will get
displayed in the Filters drop down list in the live mode. See the below image. Selecting a
filter name, will display only those records that satisfy the filter criteria.
Custom Filter
Custom filters are a set of named criteria that can be defined by the user. At present,
only simple criteria can be defined in the GUI mode. See the image below.
AdventNet, Inc. 37
Help Document Deluge Script
It only has match all and match any. The deluge script generated for the above
custom filter is highlighted below:
filters
(
EducationalQualification
Experience
BloodGroup
"Diploma with 2 years experience" :
(EducationalQualification == "Diploma" && Experience == "2 years")
)
To define slightly complex ones, like having both a AND and an OR operator, deluge
scripting is needed. See the sample given below:
filters
(
EducationalQualification
Experience
BloodGroup
"Diploma with 2 years experience" :
(EducationalQualification == "Diploma" && Experience == "2 years")
"Diploma/PostGraduate" : ((EducationalQualification ==
"Diploma" && Experience == "2 years") || Educational
Qualification == "PostGraduate")
)
}
Here "Diploma/PostGraduate" is the name of the custom filter and any boolean
expression can be given as the criteria. To know more about the expressions in deluge
scripting, refer to Expressions.
AdventNet, Inc. 38
Help Document Deluge Script
• Description
• Syntax
• Example
• Related Topics
Description
By default, a picklist field of type "Import Data from form", will display all the values of
the imported field. To set a picklist to display only specific values from the imported
field, you can specify the required criteria and display only those values that satisfy the
criteria.
Syntax
<picklist fieldname>
(
type = picklist
values = <form name>[criteria].<fieldname to be imported from form name>
)
Note:
You cannot import a picklist field, in another form. You can only import a
textfield as a picklist in another form.
Example
Assume a form named FormA has two fields "Country" and "State" to enter the name of
a country and its states. The FormA view is given below:
Now, you want to create another form named "FormB", that has the field "IndianStates"
of type picklist that needs to import only the names of the states that belongs to the
country "India" from FormA. The deluge script to do this is given below:
AdventNet, Inc. 39
Help Document Deluge Script
Deluge code:
form FormB
{
IndianStates
(
type = picklist
values = FormA[Country == "India"].State
)
FormA[Country == "India"].State - Fetches only the "State" values from "FormA" whose
"Country"is "India".
The FormB given below displays only the names of the States belonging to the country
"India".
Related Topics
AdventNet, Inc. 40
Help Document Deluge Script
Formula
• Description
• Examples
Description
You can create fields that are calculated instead of being entered by the user. These
fields are called the formula fields. When you create a formula field, you have to specify
the formula expression based on which the value for this field is calculated. You can add,
subtract, multiply or divide
Depending on the output of the formula, the value held by a formula field could be
numeric values, text values, dates, and durations.
The formula evaluation is nothing but expression evaluation and is explained in detail in
Expressions. In the below given sample, the field TotalMarks is of type formula.
TotalMarks
(
type = formula
value = English + Arts
)
English and Arts are the fields and they get generated as variables in deluge. But one
formula field cannot be used in another formula field.
i.e. The following code is invalid.
TotalMarks
(
type = formula
value = English + Arts
)
AverageMarks
(
type = formula
value = TotalMarks / 2
)
Note: Since formula fields are calculated, they do not get displayed in the
form when it is rendered. User can choose to view these fields in the form
view.
AdventNet, Inc. 41
Help Document Deluge Script
Complete Sample
Note:
• All types of form fields except multiple select fields can be used in
formulas.
• The operators/functions that can be used in formulas can be found
in the sections Operators and Built-in functions.
• The formulas will get recalculated when,
o the formula is modified
o the values of the fields participating in the formula gets
modified (when a record is updated).
AdventNet, Inc. 42
Help Document Deluge Script
Statements
Deluge Statements
• Control Statements
• Data Access
• Client Side Functions
• Miscellaneous
• Debug
AdventNet, Inc. 43
Help Document Deluge Script
Control Statements
AdventNet, Inc. 44
Help Document Deluge Script
• Description
• Syntax
• Example - Free Flow scripting
• Example - Using Script Builder
Description
The 'If' construct in deluge is the same as that of other languages. It conditionally
executes a set of statements depending on the value of the boolean expression.
Syntax
if(<if-boolean-expression>)
{
<if statements>
}
else if(<elseif-boolean-expression-1>)
{
<elseif statements-1>
}
else if(<elseif-boolean-expression-2>)
{
<elseif statements-2>
}
..
..
..
..
else if(<elseif-boolean-expression-n>)
{
<elseif statements-n>
}
else
{
<else statements>
}
AdventNet, Inc. 45
Help Document Deluge Script
executed, but if the condition was not met, then the program flow skips
the statements in the <if statements> block and searches for any else
or else if keywords.
Let us take the example of a recruitment application. The deluge code for the on success
block of the New_Applicant form is given below:
on success
{
opening = New_Opening [Position_Name ==
this.Applied_For];
if (opening.Status == "Closed")
{
sendmail
[
To : this.Email_ID,
"suganya@adventnet.com"
Subject : "Reg application for job posted at
recruitment.zohocreator.com"
Message : "The job profile " +
this.Applied_For + " for which you have
applied is not currently open "
]
}
else if (opening.Experience == this.Experience)
{
sendmail
[
To : "suganya@advetnet.com"
Subject : "Applicants resume matches job
profile"
Message : this.Applicant_Name + " matches
the job profile <br> Contach Info: "
+ this.Email_ID
]
}
else
{
sendmail
[
AdventNet, Inc. 46
Help Document Deluge Script
"suganya@adventnet.com"
Subject : "Reg application for job posted at
recruitment.zohocreator.com"
Message : "The experience required for the
job profile " + this.Applied_For
+ "does not match yours"
]
}
}
Code Explantion:
• In the on success block, we first fetch the record from the
New_Opening form, whose Position_Name matches with the
position applied for.
• if status of the position is "Closed" the statements inside the if
block is executed.
• if experience for the position is same as the experience specified,
the statements inside the else if block is executed.
• if the above two conditions fail, the statements inside the else block
is executed.
View complete sample
Refer the topic Statements -> Control Statements -> Cancel Submit to built a Validate
action script with If construct, Alert and Cancel submit.
AdventNet, Inc. 47
Help Document Deluge Script
Iterators
Iterate Form Rows (for each record)
• Description
• Syntax
• Examples - Free flow scripting
• Example - Using Script Builder
Description
Unlike other languages which supports iteration based on numerical values, say iterate
10 times, deluge supports only data driven iterators that are purely based on form data.
You can iterate through all the rows in the form or through selected rows based on the
given criteria.
Syntax
syntax 1:
where,
• formname - name of the form whose data has to be iterated one
by one.
• criteria - in most of the cases, you would like to conditionaly fetch
the data. You can specify your criteria for fetching the form data
here. It is an optional parameter.
• row-variable - this variable will hold the data for a single row
corresponding to each iteration.
syntax 2:
where,
• formvariable : it is the name of the collection variable that
contains form data. Read More.
• row-variable - this variable will hold the data for a single record
corresponding to each iteration.
AdventNet, Inc. 48
Help Document Deluge Script
Example
Visualize a simple HR application. The form 'Employee' has the following fields.
sample 1:
where,
o x : row variable
sample 2:
where,
o x : row variable
o employeerecords : It contains the form data
Refer the topic, Iterate Multiple Picklist values - Using Script builder to build an "On
Success" action script that iterates multiple picklist values in each record.
Any pure relational language will rarely require iteration as relational theory works by
fetching and manipulating collections of data using simple functions rather than iterate
over a collection and manipulate the elements one by one. However deluge is still
growing and a lot of improvements has to be done before reaching that stage. Data
driven iterator comes in-between to fill this gap.
AdventNet, Inc. 49
Help Document Deluge Script
• Description
• Syntax
• Example - Free Flow Scripting
• Example - Using Script Builder
Description
The deluge language now supports a second level of iteration to iterate through multiple
list values in a row. For example, if there are n rows in a form and for each row there are
m values in a multiple list field, you can iterate through the m values in the list within
each row.
Syntax
where,
• formname\rowvariable - name of the form whose data has to be
iterated one by one or the name of the row variable that contains
the data for a single record corresponding to each iteration.
• criteria - in most of the cases, you would like to conditionaly fetch
the data. You can specify your criteria for fetching the form data
here. It is an optional parameter.
• fieldname - name of the form field of type Import data from form
- multiselect in the above form/row, whose values has to be
iterated one by one.
• variable - name of the variable that will hold the data
corresponding to each iteration of the above fieldname.
AdventNet, Inc. 50
Help Document Deluge Script
• Name - Name of the person who would like to register himself for
coaching for one or more sport.
• Emailid - Valid email id of the person.
• Age - The age of the person registering.
• Sports - This field is a lookup field imported from Sport_Name field
in Sport_Coaching_Details form and is of type multiselect. (i.e) a
person can register for one or more number of sport, from this list.
Both the forms are related since there is a import data field between
them. So it is possible to get the Sports details from the
Sport_Coaching_Details form for any given sport in Sports_Registration
form.
For each Sport registered, we have to check if the age specified is within
the agelimit prescribed for that sport as specified in form
AdventNet, Inc. 51
Help Document Deluge Script
on success
{
if (count(Sports_Registration) >= 15)
{
// iterates through each row in the
Sports_Regitration form
for each r in Sports_Registration
{
//iterates through multiple values specified for
the Sports field in the row r
for each Sports x in r
{
if ((r.Age > x.Minimum_Age) && (r.Age <
x.Maximum_Age))
{
sendmail
(
To : r.Emailid
Subject : "Registration for
Sports coaching from " + r.Name
Message : "Your registration
for" + x.Sport_Name + "is accepted"
)
}
}
}
}
}
where,
• Sports - fieldname in the Sports_Registration form whose values
has to be iterated one by one.
• x - variable that will hold the data corresponding to each iteration
of the above fieldname
• r - row variable that contains the data for a single record for each
iteration in Sport_Registration.
AdventNet, Inc. 52
Help Document Deluge Script
3. Iterates through multiple values specified for the Sports field in the row
r. Here, Sports is the name of the field in the Sports_Registration form
whose values has to be iterated one by one and x is the name of the
variable that will hold the data corresponding to each iteration of the
Sports field.
sendmail
(
To : r.Emailid
Subject : "Registration for
Sports coaching from " + r.Name
Message : "Your registration
for" + x.Sport_Name + "is accepted"
)
AdventNet, Inc. 53
Help Document Deluge Script
Let us add the on success action script for the Sports Registration Example using
Script Builder. The following deluge features are used in this example:
• Select "On Success" Form Action
• Add "for each record"
• Add "for each list value"
• Add If condition
• Add "sendmail"
1. Select On Success Form Action
a. Select Control Flow -> For each record from the left-side tree and
drag and drop it in the editor area. The syntax to iterate each row in a
form will be displayed as shown in the screen-shot below.
b. Select Edit option to specify the row variable and criteria, if any.
f. The 'for each record' Edit dialog will be displayed as shown in the
screen-shot given below:
• Select the form name whose data has to be fetched. In this
example, the form name is Sports_Registration.
• Declare the rowvariable name as any user defined name. Here we
specify the name as r.
AdventNet, Inc. 54
Help Document Deluge Script
AdventNet, Inc. 55
Help Document Deluge Script
2. for each list value: Now we have to iterate through multiple values specified for the
Sports field within each row r. To do this,
a. Drag and drop Control flow -> for each list value to the text editor
area. The syntax is displayed as shown in the screen-shot given below.
Click on Edit to specify the required details.
b. Select the row variable r that contains the data for a single record for
each iteration in Sport_Registration.
c. Select the form field Sports in the above row variable r, whose values
has to be iterated one by one.
d. Declare a user-defined variable name x, that will hold the data
corresponding to each iteration of the Sports field in r.
e. Click on Done to add the for each syntax to the script editor.
AdventNet, Inc. 56
Help Document Deluge Script
The deluge for each list value is added to the script editor, as
shown below:
3. If condition:
b. The Edit dialog for If is displayed as shown below, wherein you have to
create the If condition. In our example, we have to check if the Age
specified in Sports_Registration is within the maximum and minimum age
limit specified in the Sports_Coaching form.
AdventNet, Inc. 57
Help Document Deluge Script
• Select the Collections Tab and select the collection variable x from
the Variables list . Here, x is the name of the variable that will hold
the data corresponding to each iteration of the Sports field.
• Click on the Minimum Age field from the list of fields in the variable
x.
• Select the && operator from the list of operators and add the
second condition to check if the Age specified is less than the
Maximum_Age.
AdventNet, Inc. 58
Help Document Deluge Script
4. Send mail : Now, we have to add the If statements to be executed, when the If
condition is satisfied. In our example, we have to send a mail to the email id specified in
the Sports_Registration form if the condition is satisfied.
a. Drag and drop the Send mail function to the editor area, as highlighted
in the screen-shot below. Refer the Send mail topic, for more information
on the syntax and usage.
AdventNet, Inc. 59
Help Document Deluge Script
b. Click on Edit to specify the To address, Subject and Message for Send
mail. The Edit dialog displays the default values. To modify the default
values, click on the icon on the right-side of each field. For example, to
send an email to the Emailid specifed in row r, select the Emailid field from
the collection variable r.
Note: The email id of the application owner will be taken as the From
Address.
c. The send mail script is added to the script editor as shown below. Click
Save Script to add the action script to the script definition.
AdventNet, Inc. 60
Help Document Deluge Script
The above action script will send an acceptence email to the registered persons if the
age specified in "Sports_Registration" is within the age limit prescribed for that sport as
specified in form Sport_Coaching_Details.
AdventNet, Inc. 61
Help Document Deluge Script
Cancel submit
• Description
• Syntax
• Examples - Free Flow Scripting
• Example - Using Script Builder
Description
The cancel submit deluge statement is used in the Form Action - Validate block to stop a
form from being submitted.
Syntax
on submit
{
// specify validation code
{
// specify alert message if not valid and cancel the
submission
alert "age should be between 20 to 100";
cancel submit;
}
Note:
The alert message in 'on submit' will be invoked only in the presence of a
'cancel submit'. In the absence of form cancellation, the alert message is
bypassed by Zoho Creator.
Age
(
type = number
)
on submit
{
if (input.Age < 20) && (input.Age >100)
{
alert "age should be between 20 to 100";
cancel submit;
AdventNet, Inc. 62
Help Document Deluge Script
}
}
2. The code snippet given below fetches the data corresponding to the
particular position applied by the applicant and checks if the Status for
that position is currently closed and displays an error message to the user.
You can access all the details related to that position by accessing the
variable “opening”.
on submit
{
opening = New_Opening [Position_Name ==
input.Applied_For];
if (opening.Status == “Closed”)
{
alert “The job profile ” + this.Applied_For + ”
for which you have applied is not currently open “;
cancel submit;
}
}
Let us built a Validate action script using Script Builder for the SampleForm1. Click here,
to view the SampleForm1. The script will validate the Contact Address field in the
SampleForm1. If the Amount is greater than 1000, the Contact Address is mandatory. In
other words, if the ContactAddress is not specified for amounts greater than 1000, the
form data will not be submitted.
1. Add Validate form action : Click on the Script Tab to display the Script Editor.
Select the Form Action On Add -> On Validate as highlighted in the screen-shot below.
2. Add If <condition>
AdventNet, Inc. 63
Help Document Deluge Script
b. The Edit dialog for If is displayed as shown below, wherein you have to
create the If condition.
• Click on the Amount field from the list of Input fields. The text
input.Amout will be added to the text area as highlighted below.
• Select the > operator from the list of operators and specify the
value as 1000. Now, the first condition (input.Amount >1000) in
the If statement is added.
• Double-click on the ContactAddress field from the list of Input
fields. The text input.ContactAddress will be added to the text
area below.
• Select the == operator and specify a blank text in double quotes.
You can do this, by selecting the icon from the operator list.
• Since the If statement must satisfy both the conditions, they must
be joined by an "AND" operator. To do this, place the cursor
inbetween the two conditions and select the && operator from the
list of operators.
c. Click Done to add the If condition to the script editor as show below.
AdventNet, Inc. 64
Help Document Deluge Script
3. Add Alert message: Now, we have to add the If statements to be executed, when
the If condition is satisfied. In our example, if the Amount is greater than 1000 and if the
ContactAddress is not specified, an alert message will be displayed and the form
submission will be cancelled.
• To add an alert message, drag and drop the Alert keyword to the
editor area.
• Click on Edit to specify the Text to be displayed.
•
o The text must be specified within double quotes. Click Done to add it to
the script editor.
AdventNet, Inc. 65
Help Document Deluge Script
• Drag and drop Cancel submit to the script editor area and place it after the alert
message.
•
5. Click Save Script to add the On validate script action to the form definition.
AdventNet, Inc. 66
Help Document Deluge Script
6. To view the complete script, select Form Definition -> With Action or select Free-flow
Scripting. The validate action script is successfully added to the form definition, as shown
below.
SampleForm1
When the form data is submitted, if the Amount is greater than 1000 and the
ContactAddress is not specified, the alert message is displayed and the form is not
submitted, as shown below.
AdventNet, Inc. 67
Help Document Deluge Script
Set Variable
• Description
• Syntax
• Example
Description
The Deluge Set <Variable name> is used in form action and field action scripts, to set a
value to a variable. Variables are nothing but container for data. The value of a variable
changes during the execution of a script and hence the name 'variable'. Variables can be
given value, and values once given can be altered any number of times.
The variables make your language dynamic by changing their value according to the
context. Variables in deluge are strongly typed , in the sense, variables defined to hold
number will hold only numbers till the script termination and variables defined to hold
string will hold only string values till the end of script execution. The two types of
variables used in deluge scripting are :
- Form fields are the variables that get declared automatically and these variables can be
used in scripting.
- Variables defined in the action scripts.
Syntax
variable = value;
where,
• variable is any user-defined variable defined in the action script or
input form fields.
• value - the value assigned to the variable. The value can be any of
the following:
o value specified in input form fields
o value held by user defined variables.
o value returned by zoho variables.
o numeric / string /date value. The string value must be
enclosed in double quotes and date value must be enclosed
in single quotes.
AdventNet, Inc. 68
Help Document Deluge Script
Example
In the following sample code, we have set form fields, user defined
variables, zoho variables as values to variables.
form Sample
{
Date1
(
type = date
)
English
(
type = number
width = 20
)
Maths
(
type = number
width = 20
)
on add
{
on validate
{
dd = '12-Apr-2007';
if (input.Date1 == dd)
{
alert "Please enter a different date";
cancel submit;
}
}
on success
{
total = (input.English + input.Maths);
average = (total / 2);
success message "Total" + " " + total + " " +
"Average" + " " + average;
if (average > 50)
{
Grade = "Good";
}
else
{
Grade = "Bad";
AdventNet, Inc. 69
Help Document Deluge Script
}
datex = zoho.currenttime;
info "Grade" + " " + Grade + " " + datex + "
";
}
}
1. The following line of code sets the sum of the value of the input form
fields English and Maths, to the variable total.
2. The following code sets a user defined variable total as the value of the
variable average.
datex = zoho.currenttime;
dd = '12-Apr-2007';
AdventNet, Inc. 70
Help Document Deluge Script
Data Access
• Fetch Records
• Modify Records
AdventNet, Inc. 71
Help Document Deluge Script
Fetch Records
• Description
• Syntax
• Example - Free flow scripting
• Examples - Using Script Editor
Description
Forms are structures that contain data in Zoho Creator. The form data is stored in a
relational database and Deluge provides an easy wrapper called collection variable for
accessing these data. Unlike onsubmit script (which is invoked before persisting the form
data in database), onsuccess and onchange actions act on stored data and they require
collection variables for accessing the data. The collection variables hold one or more
records fetched from a form.
Syntax
<collectionvariable> = <formname>[criteria];
where,
• formvariable - it is the name of the collection variable that
contains form data.
• formname - name of the form whose data has to be fetched.
• criteria expression - the criteria expression that evaluates to a
value
Example
Below given is an example of a Bug tracker application to illustrate how data from a
form can be fetched and used. It has two forms.
• Form team_member which in turn has two fields name and mailid
form team_member
{
name
(
type = text
)
mailid
(
type = email
AdventNet, Inc. 72
Help Document Deluge Script
)
}
• There is a second form post_issue which has the fields id, issue_title,
description, submitted_by, submitted_date, priority, assigned_to and status.
form post_issue
{
id
(
type = number
)
issue_title description
(
type = textarea
)
submitted_by
submitted_date
(
type = date
)
priority
(
type = radiobuttons
values = {v.high, high, medium, low}
)
assigned_to
(
type = picklist
values = team_member.name
)
status
(
type = radiobutton
values = {open, in progress, closed, suspended}
on change
{
tm = team_member[name == input.assigned_to];
sendmail
[
To : tm.mailid
Subject : "status of the issue " + input.id +
" modified to " + input.status
Message : input.description
]
}
)
}
AdventNet, Inc. 73
Help Document Deluge Script
Code Explanation
The post_issue form has the details of the issue where one of the fields is
the name of the team member from the team_member form. All the
details of the team member is present in the team_member form.
Both the forms are related since there is a import data field between
them. So it is possible to get the team member details from the
team_member form for any given member name in the assigned_to field
in the post_issue form.
The fields in a form are referred to as columns in an nview. Also note the
input keyword. All the columns in an nview have to be referred using
input keyword as deluge automatically initializes an nview variable named
'input'.
where, tm is the team_member nview and will have one record that
corresponds to the team member to whom the particular issue is assigned.
on change
{
tm = team_member[name == input.assigned_to];
sendmail
[
To : tm.mailid
Subject : "status of the issue " + input.id + "
modified to " + input.status
Message : input.description
]
}
You can access all the info (data) about the team member form using the
tm nview.
Refer the topic, Data Access -> Modify Records -> Example Using Script builder.
AdventNet, Inc. 74
Help Document Deluge Script
Modify Records
• Description
• Syntax
• Example - Free Flow Scripting
• Examples - Using Script Editor
Description
In the previous topic, Fetch Records we learnt how to retrieve the form data and store it
in a form variable. This form variable, also called collection variable, contains the
retrieved form data. You can now modify the retrieved data by accessing the required
field values through the form variable.
Syntax
<formvariable>.fieldname = <expression>
where,
• formvariable - it is the name of the collection variable that contains
form data. Read More
• fieldname - name of the field to be updated
• expression - any valid deluge expression that evalutes to a value
If you are updating the value of the current form record being submitted,
you need not explicitely fetch them. You can directly use the fieldname for
updating as given below:
fieldname = <expression>
where,
• fieldname - name of the field to be updated
• expression - any valid deluge expression that evalutes to a value
Take a very simple use case : User is borrowing a book from the library. In library
manager terminology, it is called 'Issuing a Book'.
AdventNet, Inc. 75
Help Document Deluge Script
1. The following books are owned by the library. The column 'Status' with values
'Available' and 'Issued', indicates whether the book is available in the library or is issued
to any user.
2. Already the following books were issued to the users on the mentioned issue date.
Note: This view is created from the form 'Issue Book' shown below this view.
3. Now, we are getting a scenario where the user 'James' is borrowing the book 'The City
of Joy'. Use the 'issue book' form given below to get book name and user name.
Note: The above view 'Books Issued Details' represent the data in this form. Also in this
form, the field 'Issue date' is hidden and not shown to the user for filling.
AdventNet, Inc. 76
Help Document Deluge Script
As you can see, these two operations need not be done explicitly by the user as they can
be automatically calculated. This is where our field modification support comes into play.
Especially in the second operation, we have to get the corresponding book (i,e. The City
of Joy) from the book form data and modify it.
We can use the 'on success' event block of the 'Issue Book' form to write the three lines
of code , that is going to do the magic.
sample 1:
on success
{
//fetch the book row from the 'Book' form
myBook = Book [Name == input.book];
//modify the 'Status' of this book to 'Issued'.
myBook.Status = "Issued";
Below , you can see the changes done after submitting the form.
• 'Status' of the book 'The City of Joy' is modified.
• Current date is automatcally stored in the 'Issue date' field (See the new entry
added at the top).
AdventNet, Inc. 77
Help Document Deluge Script
Let us add the on success script for the Library Manager application - Issue Book Form,
using script builder.
2. Fetch Records - To fetch records from the form Bookswhose name is equal to the
name of the book specified in the current form (Issue_Book form), and store it in a
collection variable,
a. Select Data Access -> Fetch Records from the left-side tree and drag
and drop it in the editor area. The syntax to fetch records from a form, will
be displayed as shown in the screen-shot below:
AdventNet, Inc. 78
Help Document Deluge Script
b. Select Edit option to specify the variable name, formname and criteria
to fetch the records.
• Select the tab Criteria fields. This will display all the fields in the
Books form.
AdventNet, Inc. 79
Help Document Deluge Script
AdventNet, Inc. 80
Help Document Deluge Script
Update Record: We have fetched the record from the Books whose name is the name
of the book currently issued. Hence, the status of this book has to be updated from
"Available" to "Issued". To update a record,
a. Select Data Access -> Update Records from the left-side tree and
drag and drop it in the editor area. The syntax to update records from a
form, will be displayed as shown in the screen-shot below:
b. Select Edit option to specify the variable name and the value to be
updated.
AdventNet, Inc. 81
Help Document Deluge Script
Set Variable: To set the Date field in the Issue_Book form with the current date,
AdventNet, Inc. 82
Help Document Deluge Script
a. Select Set Variable from the left-side tree and drag and drop it in the
editor area. The set syntax will be displayed as shown in the screen-shot
below:
c. Select the Variable name as the IssueDate field in the current form
(Issue_Book).
d. To set the current time to the IssueDate field, select Zoho variables -
> zoho.currenttime from the variables list.
e. Click Done to add the syntax to the text editor.
AdventNet, Inc. 83
Help Document Deluge Script
View Script:
To view the complete script , select Form Definition -> With Action or select Free-flow
Scripting. The on success action script is successfully added to the form definition, as
shown below.
AdventNet, Inc. 84
Help Document Deluge Script
View Form:
AdventNet, Inc. 85
Help Document Deluge Script
AdventNet, Inc. 86
Help Document Deluge Script
• Overview
• Syntax
• Examples
Overview
The deluge hide keyword is used in on change field action script and on load form action
script to hide a form field, when not required. The field will not be available for
viewing/editing to both the owner of the application and to people with whom you are
sharing the application. The show keyword is used to display a field that was previously
hidden.
Syntax
Examples
1. In the following sample code, the unwanted Activity fields are hidden
during form load, so that the form will be initially shown with only the
Activity1 field.
Activity1
(
type = picklist
values = {"action1", "action2"}
)
Activity2
(
type = picklist
values = {"action3", "action4"}
)
Activity3
(
type = picklist
values = {"action5", "action6"}
)
on load
{
hide Activity2;
hide Activity3;
}
AdventNet, Inc. 87
Help Document Deluge Script
2. In the following code, the on change form action is executed when the
No_of_Activities field value is changed. The fields that were previously
hidden during form load, will be displayed based on the value entered in
this field.
No_of_Activities
(
displayname = "No of Activities"
type = picklist
values = {"1", "2", "3", "4"}
on change
{
activitiesno = input.No_of_Activities.toLong();
if (activitiesno >= 2)
{
show Activity2;
}
else
{
hide Activity2;
}
if (activitiesno >= 3)
{
show Activity3;
}
}
3. The following sample code will by default hide the 'Medical Professional
Type' field when the form is loaded and will show the field only when the
'Medical Professional' box is checked.
Medical_Profession
(
displayname = "Medical Profession"
type = checkbox
defaultvalue = false
on change
{
if (input.Medical_Profession)
{
show Medical_Profession_Type1;
}
else
{
hide Medical_Profession_Type1;
}
}
)
AdventNet, Inc. 88
Help Document Deluge Script
Medical_Profession_Type1
(
displayname = "Medical Profession Type"
type = picklist
values = {"A", "B", "C", "D"}
)
on load
{
hide Medical_Profession_Type1;
}
4. The following sample code will hide the form fields when the form is
loaded after a specific date.
on load
{
if (zoho.currenttime > ‘01-Jan-2007 00:00:00?)
{
hide name;
hide emailid;
hide blog_url;
hide about_yourself;
hide emailiderror;
set showmessage = “Registration is CLOSED!”;
}
}
AdventNet, Inc. 89
Help Document Deluge Script
• Overview
• Syntax
• Example - Free Flow Scripting
• Example - Using Script Builder
Overview
The deluge set keyword is used in on change field action script and on load form action
script to assign a value to a form field. The value can be any user specified value or the
value returned by input form fields, user defined variables and zoho variables.
Syntax
Example
1. To set the value of the date field with the current date.
form CurrentDate
{
date1
(
type = date
)
on load
{
set date1 = zoho.currentdate;
}
}
form Data
{
AdventNet, Inc. 90
Help Document Deluge Script
{
set Grade = "Better";
on load
{
if (zoho.currenttime > ‘01-Jan-2007 00:00:00?)
{
hide name;
hide emailid;
hide blog_url;
hide about_yourself;
hide emailiderror;
set showmessage = “Registration is CLOSED!”;
}
}
Let us built an on load action script using Script Builder for the SampleForm1. When the
form is loaded to add a new entry, the script will set the Date field with the current date.
Click here, to view the SampleForm1.
Select the Form Actions -> On Add -> On Load as highlighted in the screen-shot below.
a. Drag and drop the client function Set field as highlighted in the screen-
shot below. Refer the set <fieldname> deluge function, for more
information.
AdventNet, Inc. 91
Help Document Deluge Script
b. Click on Edit to specify the values. The Edit dialog for Set field is
displayed as shown below, wherein you have to select the fieldname to be
set and the value. To do this,
• Click on the Date1 field from the list of fields.
• Select the tab Zoho Variables. This will display all the supported
supported zoho Variables. Click on zoho.currentdate to display
the same in the text box as shown below.
• Click Done to add the selected values in the script editor.
AdventNet, Inc. 92
Help Document Deluge Script
c. The set syntax is now updated with the required fieldname and value as
shown below. Click Save Script to update the changes.
View Script
To view the complete script with the onload action, select Form Definition -> With Action
or select Free-flow Scripting. The on load action script is successfully added to the form
definition, as shown below.
AdventNet, Inc. 93
Help Document Deluge Script
View SampleForm1
When the SampleForm1 is loaded, the Date1 field is set with the current date as shown
below.
AdventNet, Inc. 94
Help Document Deluge Script
• Description
• Syntax
• Example - Free Flow scripting
• Example - Using Script Editor
• Related Links
Description
By default, a picklist field of type "Import Data from form", will display all the values of
the imported field. The deluge add keyword is used to dynamically filter and add picklist
values based on the selection in a previous pick list field.
Note:
You cannot import a picklist field, in another form. You can only import
a textfield as a picklist in another form.
Syntax
<picklist fieldname>.add(instancevariable.fieldname);
Refer the example in the topic, Client Side Functions -> Clear Picklist to add an On User
Input field action script. The sample script adds picklist values dynamically.
Refer the example using script builder in the topic, Client Side Functions -> Clear Picklist
to add an On User Input field action script. The sample script adds picklist values
dynamically.
Related Links:
AdventNet, Inc. 95
Help Document Deluge Script
Description
A clear <picklist> function clears all the values in a picklist and displays an empty
picklist. It can be is used in On Load form action to display an empty picklist when the
form is loaded and in On User Input field actions to display an empty picklist
dynamically, based on a specified criteria.
Syntax
2. Form to fill in the team member details. It has the name of the
team member and the module he works for. See a list view of all
the team members (and the respective modules).
3. Form for filing issues. Each of the issues filed has to be assigned to
the appropriate team member. Since we have already defined the
AdventNet, Inc. 96
Help Document Deluge Script
person in charge for each of the modules, it will make more sense
if the items in the ‘Assigned to’ picklist gets updated every time the
module is changed, listing only the relevant entries.
form FileIssue
{
Title
(
type = text
)
Description
(
type = textarea
)
Module
AdventNet, Inc. 97
Help Document Deluge Script
(
type = picklist
values = Module.Module_Name
on user input
{
if (count(TeamMember[Module == input.Module]) ==
0)
{
clear AssignedTo;
}
else
{
team = TeamMember [Module == input.Module];
for each t in team
{
AssignedTo.add(t.Name);
}
}
)
Priority
(
type = radiobuttons
values = {"Very High", "High", "Medium",
"Low"}
)
Status
(
type = checkboxes
values = {"Open", "Close", "In-Progress"}
)
ReportedDate
(
displayname = "Rep.Date"
type = date
)
AssignedTo
(
type = picklist
values = TeamMember.Name
)
Explanation:
1. If <condition>:
The code snippet given below uses the count deluge function to count the
number of records in the TeamMember form, whose Module name is
equal to the Module selected in the FileIssue form. fetches all the
members of the team, in charge of the selected module.
if (count(TeamMember[Module == input.Module]) == 0)
AdventNet, Inc. 98
Help Document Deluge Script
{
clear AssignedTo;
}
2. If statement:
if (count(TeamMember[Module == input.Module]) == 0)
{
clear AssignedTo;
}
2. else statements
The code snippet given below fetches all the members of the team, in
charge of the selected module.
else
{
team = TeamMember [Module == input.Module];
for each t in team
{
AssignedTo.add(t.Name);
}
}
AdventNet, Inc. 99
Help Document Deluge Script
Let us add the deluge code for the above example, using script builder. Click here, to
view the form.
• On User Input field action
• if <condition>
• clear picklist
• Fetch Records
• for each record
• Add to picklist dynamically
1. Add On User Input field action: To add an action when the Module field in FileIssue
form is changed,
a. Select the form FileIssue from the list of forms displayed in the top left
corner of the script editor.
b. Select Field Actions -> Module -> On User Input, as shown in the
screen-shot below.
2. Add if <condition>
a. Drag and drop the If control flow statement, as highlighted in the
screen-shot below. Refer the If, else if, else topic, for more information on
the syntax and usage.
c. The Edit dialog for If is displayed as shown below, wherein you have to
create the If condition.
The if condition will count the number or records in the TeamMember form
with module name same as the module name entered by the user in the
current form. The if statements will be executed, if the count is 0. (i.e) if
no such records exists.
Clear Picklist: In our example, the AssignedTo picklist must not display any value if no
records exists in the TeamMember form with the input module name.
a. To clear a picklist field, drag and drop Client Functions -> Clear
Picklist.
b. Click on Edit to specify the picklist fieldname.
d. Add the else syntax to the script editor, to execute statements if the if
condition is satisfied.
3. Fetch Records - To fetch records from the form TeamMember whose module name is
equal to the module name input, and store it in a collection variable,
a. Select Data Access -> Fetch Records from the left-side tree and drag
and drop it in the editor area. The syntax to fetch records from a form, will
be displayed as shown in the screen-shot below:
b. Select Edit option to specify the variable name, formname and criteria
to fetch the records. The Fetch records dialog will be displayed as shown in
the screen-shot given below:
• Select the form name whose data has to be fetched. In this
example, the form name is TeamMember.
• Specify the collection variable to store the fetched records, as any
user defined name. Here we specify the name as team.
• Now you have to specify the criteria based on which the data is to
be fetched from the TeamMember form. In our example, we have
to fetch the records from TeamMember whose Module name is
same as the Module currently chosen(input) in the FileIssue form.
To do this, select the tab Criteria fields. This will display all the
fields in the TeamMember form.
• Select Module to add it to the value textbox.
• Select the == symbol to add it to the value textbox.
• Select the tab Input fields to display fields available in the input
form. In our example, the FileIssue is the form whose values are
currently input by the user.
• Click on Module from the list. You will now find the syntax
input.Module added in the text area.
• Click Done to add the syntax to the text editor.
4. for each statement: Now, we need to iterate through each row in the formvariable
team and add the name of the team member to the AssignedTo picklist field. To do this,
a. Drag and drop Control flow -> for each record to the text editor
area. The syntax for the for each statement is displayed as shown in the
screen-shot given below. Click on Edit to specify the required details.
c. Click Done to add the for each syntax to the script editor.
5. Add to Picklist: For each row t in the formvariable team, we have to add the Name
to the Assignedto picklist field.
a. Drag and drop Client functions -> Add to picklist to the text editor area.
The syntax for the add statement is displayed as shown in the screen-shot
given below. Click on Edit to specify the picklist name and value.
c. The deluge statements to fetch records, iterate each row and add to
picklist dynamically, is added to the script editor as highlighted below.
Click Save Script to add the On User Input action to the script.
e. To view the complete script with the onload action, select Form
Definition -> With Action or select Free-flow Scripting. The on load action
script is successfully added to the form definition, as shown below.
6. When a Module is selected in the fileIssue form, only those members of the team, in
charge of the that module will get listed in the ‘Assigned to’ picklist.
Overview
The alert box dispalys an alert message, when the value of a field is changed or when a
form is loaded. It is used in the on change field action or on load form action script.
Syntax
alert <value>;
where,
• value - the alert message to be displayed.
Example
Alerts the week of the year of a date field when a date is entered by the
user.
form FormA
{
Date1
(
type = date
on change
{
alert(input.Date1.getWeekOfYear() + "th week of
the year");
}
)
Miscellaneous
• Send mail
• On success message
Sending Mail
• Syntax
• Example
• Example - Using Script Builder
Syntax
Use the sendmail function to send emails from your zoho creator application.
sendmail
[
to : <string expression>
subject : <string expression>
message : <string expression>
]
where,
• to - the mail recipient
• subject - the text you want to display in the message subject
• body - the text you want to display in the message body
• <string expression> - deluge expression evaluating to valid email address in case
of from and to and to any valid string in case of subject and message. subject
and message are optional parameters. To know in detail about the expressions
in Deluge, refer to Expressions.
Note: The email sent will have the email id of the application owner as the
From address.
Example
sendmail
[
to : "yourself@zohocreator.com"
subject : "Welcome"
message : "Happy development with deluge zoho creator"
]
Refer the Example Using Script Builder in the topic, On Success Message.
Success Message
• Overview
• Syntax
• Example - Free flow scripting
• Example - Using Script Builder
Overview
Syntax
on add
{
on success
{
//specify the message here
success message "";
}
}
on add
{
on success
{
success message "employee record added";
}
}
Let us built an on success action script using Script Builder for the Send_Feedback form
in Feedback Application. Click here, to view the feedback form.The on success script will
send a mail to the email id specified in the Sender field, when a new form data is
persisted in the database.
a. Drag and drop the Send mail function to the editor area, as highlighted
in the screen-shot below. Refer the Send mail topic, for more information
on the syntax and usage.
b. Click on Edit to specify the To, Subject and Message for Send mail. The
Edit dialog displays the default values. To modify the default values, click
on the icon on the right-side of each field. For example, to edit the To
Address, select the icon highlighted below:
c. The Edit dialog for To Address is displayed. The value specified in the
sender field will be taken as the value for To Address. To do this, double-
click on the sender field from the list of Input fields. The text
input.sender will be added to the text area as highlighted below. Click
Done to add this to the To Address.
d. Similarly, you can add the "Message" in the sendmail as the value
specified in the category and comments field. Click Done to update the
changes in the Message box of the Send Mail Edit dialog.
e. When you have specified the values to the To, Subject and Message of
the Send Mail dialog, click Done to add the values to the script editor.
f. The send mail script is added to the script editor as shown below. Click
Save Script to add the script changes.
Add "Success Message" : On successful submisson of form data, the message "Data
Added Successfully" is displayed by default. If you want to customize this message, you
have to specify the same in the success message string as shown below. To do this,
a. Drag and drop the Success message to the editor area. Click on Edit
and specify the message.
b. The Edit dialog for the success message is displayed. You can specify
any text within quotes. The input field values can also be appended to the
message string using the "+" operator. Click on Done to add the script in
script editor.
c. The on success script is added to the script editor. Click on Save Script
to update the changes. When the form data is persisted in the database,
the script will send a mail and display the specified success message.
View Script
To view the complete script, select Form Definition -> With Action or select Free-flow
Scripting. The on success script is successfully added to the form definition, as shown
below.
The on success script will send a mail to the email id specified in the Sender field, after
the form data is persisted in the database.
The success message specified in the script is displayed as shown in the screen-shot
below:
Add Comment
• Description
• Syntax
• Example - Free Flow Scripting
• Example - Script Builder
Description
Add comments to your deluge scripts to document your script and enhance code
readability. The Comment line is prefixed with a #.
Syntax
#<comment text>
In the following example, the comment tag explains the code in detail.
Age
(
type = number
)
on submit
{
# checks if the age specified is less that 20 or
greater than 100
if (input.Age < 20) && (input.Age >100)
{
# displays the specified alert message if
validation fails and cancels form submission
alert "age should be between 20 to 100";
cancel submit;
}
}
To add a comment line in script builder, use the Add comment task as shown in the
screen-shot below. Click on the Edit button and specify the comment text.
Debug
• Alert
• Info
Alert
• Description
• Syntax
• Examples - Free flow scripting
• Example - Using Script Builder
Description
The alert keyword is used in the Form Action - Validate block to display a meaningful
alert message when the form data is not submitted. The alert message gives a clear
feedback to the user as to why the form does not accept the data. The message must be
of type string enclosed within "" and will get displayed in the bottom part of the form
Syntax
alert <value>;
where,
• value - the alert message to be displayed.
Note: The alert message in 'on submit' will be invoked only in the presence
of a 'cancel submit'. In the absence of form cancellation, the alert message
is bypassed by Zoho Creator.
Age
(
type = number
)
on submit
{
if (input.Age < 20) && (input.Age >100)
{
alert "age should be between 20 to 100";
cancel submit;
}
}
2. The code snippet given below fetches the data corresponding to the
particular position applied by the applicant and checks if the Status for
that position is currently closed and displays an error message to the user.
You can access all the details related to that position by accessing the
variable “opening”.
on submit
{
opening = New_Opening [Position_Name ==
input.Applied_For];
if (opening.Status == “Closed”)
{
alert “The job profile ” + this.Applied_For + ”
for which you have applied is not currently open “;
cancel submit;
}
}
Refer the topic Statements -> Control Statements -> Cancel Submit to built a Validate
action script with If construct, Alert and Cancel submit.
Info
• Description
• Syntax
• Examples
Description
The 'info' keyword is used in 'on validate', 'on success' and 'on update' actions to display
debug messages to enable the owner of the application in debugging. The info message
can be viewed only by the owner of the application by clicking on the link "View log
details", which appears after the data is persisted in the database. So, if your form is
being filled by non-owners, they will not be able to view this message.
Syntax
info <message>;
Examples
Example 1
In the following example, the info message is displayed after the sendmail
function is invoked.
on submit
{
sendmail
(
To : "latha@adventnet.com"
Subject : "Report for Product Status: " +
input.Product_Status_is
Message : "Product: " + productno
)
}
info "Report has been sent.";
}
}
Example 2
In the following example, the info message is displayed only if the form
data does not get cancelled.
on submit
{
if (count(sign_up[(Username == input.Username &&
Password == input.Password)]) == 0)
{
alert "the username/password does not exist";
cancel submit;
}
info input.Username + " " + input.Password;
}
Expressions
• Expression types
• Variables
• Literals or Constants
Expression types
String Expression
sendmail
[
To : this.name+"@adventnet.com"
Subject : "The feedback you had sent has been
incorporated in zohocreator"
Message : "Comments" + this.comments
]
Numeric Expression
English
(
type = number
decimalplace = 2
)
Arts
(
type = number
decimalplace = 2
)
AverageMarks
(
type = formula
value = (English + Arts) / 2
)
DateTime Expression
A datetime expression involves operations with date, time, day, week and
such calenderial terms. A fixed number of days, week or time can be
added or subtracted from date. The final value of such expression should
be a valid date with time information.
filters
(
"joined on 4th july" : (Date_Of_Joining == '04-Jul-
2006')
)
Boolean Expression
The result of a boolean expression has only two states, true or false. The
boolean expressions are nothing but conditional expressions used to
evaluate or analyze certain condition and return true or false depending on
whether the condition checked succeeded or failed.
e.g. 2 > 4, 4< 6 && (5%6) > 3. Also any value that is not nil or the
constant false is true.
filters
(
priority
status
"High Priority" : ((priority == "V.High" || priority ==
"High") && (status == "Open"))
)
Variables
Literals or Constants
Literals indicate values written directly like "Hello world", 4. e.g "Hello world" is a string
literal and 4 is a numeric literal.
sendmail
[
To : this.name+"@adventnet.com"
Subject : "The feedback you had sent has been incorporated in
zohocreator"
Message : "Comments" + this.comments
]
Operators
• Description
• Arithmetic Operators
• Binary Arithmetic Operators
• Unary Arithmetic Operators
• Relational Operators
• Conditional Operators
• Date Time Operators
Description
Operators are a form of functions which acts on one or two values and return a value.
Very commonly used functions are given operator status and are invoked by special
symbols such as '+' for addition, '-' for subtraction etc.
Example:
(7 * 7) + 4 = 53
Hello " + "world" = "Hello world"
Arithmetic Operators
An arithmetic operator, operates on one or two numeric value and returns a numeric
value.
Binary Arithmetic Operators
Syntax
where, <op1> and <op2> are both numeric expressions. The table below
lists the binary arithmetic operators and their functionality:
Operator *
multiplies <op1>
and <op2>
/ Functionality
Relational Operators
A relational operator compares two values and returns a boolean expression (true or
false) depending on the relation between the two values.
Example
Syntax
The table below lists the binary arithmetic operators and their functionality:
Operator Functionality
Conditional Operators
Relational operator combined with conditional operators, make your decision making
more powerful. A conditional operator operates on boolean expression and each boolean
expression may contain relational operator or conditional operator, thus enabling us to
write complex decision logics. Deluge supports the conditional operators '&&' , '||' and
'!'.
Syntax
where,
'&&' - returns true only if both the left and right boolean expressions are
true.
'||' - returns true if atleast one of the boolean expression evaluates to
true.
'!' - returns true if the boolean expression is false and vice-versa.
Operator Functionality
Datetime operators: The Datetime operators are used to manipulate date values.
Syntax
where,
- Operator
Operator Functionality
+
adds a delta time to the specified date/time
- subtracts a delta time to the specified date/time
- delta value is a quantity of time, say 1 hour, 3 week etc. The delta value should be
given in single quotes.
Syntax
'nW:nD:nH:nM:nS'
where,
W - Weeks
D - Days
H - Hours
M - Minutes
S - Seconds
n is a positive number
All values are optional, but if given they should follow the above order.
Example
Built-In Functions
• String functions
• Boolean string functions
• Date functions
A function is a set of code, that take a finite number of input and optionally returns a
value. None of these functions are case-sensitive.
String functions
Functions that operate on string expression are classified as string functions, they
include functions for finding the length of a given text, remove certain words from a text
etc.
In all the given functions, the original string is not changed by the functions,
whereas only the return value is affected by these functions.
Concatenate
Operator Functionality**
two strings
Concatenate
+ <string1> + <string2>
two strings
Eliminate the
substring from
remove(<string>) <string>.remove(<substring>)
the given
string.
Eliminate the
first occurence
of the
removeFirstOccurence() <string>.removeFirstOccurence(<substring>)
substring from
the given
string.
Eliminate the
last occurence
of the
removeLastOccurence() <string>.removeLastOccurence(<substring>)
substring from
the given
string.
Get the string
after the
getSuffix() <string>.getSuffix(<substring>)
specified
substring.
Get the string
before the
getPrefix() <string>.getPrefix(<substring>)
specified
substring.
Convert the
string to
toUpperCase() <string>.toUpperCase()
uppercase.
Convert the
toLowerCase() <string>.toLowerCase() string to
lowercase.
Concatenate
Operator Functionality**
two strings
Retain only
the
alphanumeric
getAlphaNumeric() <string>.getAlphaNumeric()
present in the
specified
string.
Retain only
the alphabets
getAlpha() <string>.getAlpha() present in the
specified
string.
Remove all
the
alphanumeric
removeAllAlphaNumeric() <string>.removeAllAlphaNumeric()
present in the
specified
string.
Remove all
the alphabets
removeAllAlpha() <string>.removeAllAlpha() present in the
specified
string.
Get the length
length() <string>.length() of the given
string.
Gets the
number of
times a
getOccurenceCount() <string>.getOccurenceCount(<substring>)
substring is
present in the
given string.
Gets the index
of the first
occurence of
indexOf() <string>.indexOf(<substring>)
the substring
in the given
string.
Gets the index
of the last
occurence of
lastIndexOf() <string>.lastIndexOf(<substring>)
the substring
in the given
string.
These functions operate on two string expression and return a boolean expression.
Date functions
<date>.getYear()
returns a number representing
getYear()
where, <date> is a form field of type the year of the date.
"date"
returns a number in the range
<date>.getWeekOfYear() (1 - 52), representing the
number of the week in the year.
getWeekOfYear()
where, <date> is a form field of type
"date" For example, "16/1/2007"
returns 3.
returns a number in the range
(1 - 7), representing the number
<date>.getDayOfWeek() of the day of the week, that date
falls.
getDayOfWeek()
where, <date> is a form field of type
"date" The number "1" represents
Sunday, "2" represents Monday
and so on.
Count function
• Description
• Syntax
• Examples
Description
Syntax
count(formname[<expression>])
Example
1. The following sample code, added to the on submit block, checks for uniqueness of a
record. If the name specified in the form data already exists in the team_member form,
the data is not submitted.
on submit
{
if (count(team_member[name == input.name]) > 0)
{
cancel submit;
}
}
where,
2. The following sample code, added to the on sumbit block, limits the number of
records in a form.
on submit
{
if(count(Employee)>= 20)
{
alert("No more registrations allowed");
cancel submit;
}
}
where,
Deluge Variables
• Date Variables
• String Variables
• Examples
Date Variables
zoho.currentdate()
zoho.currenttime()
String Variables
zoho.loginuser()
zoho.loginuserid()
zoho.adminuser()
zoho.adminuserid()
Examples
Example 1:
In the following sample code, the username and userid field will display the
current login user name and his emailid.
username
(
type = formula
value = zoho.loginuser
)
userid
(
type = formula
value = zoho.loginuserid
)
Example 2:
In a leave application, users will submit their leave in the leave form. When a
user logs in and when they login, they will see only the leave details belonging to
them.
{
show all rows from emp_leave_form [Employee_email ==
zoho.loginuserid]
(
Employee_email as "Employee email"
Leave_type as "Leave type"
From_Date as "From Date"
To_Date as "To Date"
Reason
)
filters
(
Leave_type
From_Date
)
}
Code Explanation:
where,
FAQ's
• Forms
• Form Fields
• Views
• Script Actions
• General
FAQ - Forms
Form is the structure that contains the data. It can be referred to in two ways.
• display name
It is the name by which a form will be referred through out in the GUI mode and
also while a user is accessing the application in Live Mode. The display name
should be given within double quotes.
• label name
It is the actual name of the form. The label name of a form is unique
within an application. Only the label name will be referred while scripting.
A label name of a form should be alphanumeric and can contain
underscore.
form add_employee
{
displayname = "Add Employee"
}
where,
Renaming a form is a safe operation and would not affect the data in anyway.
Renaming the display name of a form is very straight forward. Just change
the display name in the form definition and save the script as shown
below.
form add_employee
{
displayname = "Add Employee" "Add New Employee"
}
If no data is present, a form can be deleted by just removing the form definition from
the text area and saving the page. If data is present, Zoho Creator will issue a error
message that it is not possible to delete the form since data is present. See a sample
error message below.
To delete the form in such cases, you have to explicitly use the delete keyword, as
shown below,
or just add a delete keyword before the form definition, as shown below.
Note: When you delete a form, all the data corresponding to the form also
gets deleted and it cannot be recovered.
Form have display names and label names. You can have more than one form having the
same display name in an application but the label name should be unique within an
application.
General
1. How do I define form fields in script mode?
2. Is there any naming conventions to be followed while defining form fields?
3. What are the different types of form fields supported in Zoho Creator?
4. How do I rename form fields in script mode?
5. Can I delete a form field that contains data ? If so, how?
6. Why is default value and tooltip not generated for some fields?
7. Is there a way to configure a hidden field so that only the owner would be able to
view/edit it?
8. Is it possible to hide/display a field based on a condition?
9. Sometimes, my requirement is such that combination of a field has to be unique.
For example. Name of person and date of birth combination has to be unique. Is
it possible to set that in GUI or script?
Formula Field
1. I have a form with a formula field. I have also created a view for it and it has
some data. I modify the formula field. But I am unable to view the table for
sometime. Why is it so?
2. Can one formula field be used in another formula in the same form?
3. I'm trying to create a database for order entry. I want to have each order
stamped with the time that it was submitted at. How can I go about doing that
with ZOHO creator?
Picklist Field
Date Field
General
The fields in a form define the individual properties of the specific kind of information. A
form field is also referred in two ways.
• display name
It is the name by which a field will be referred through out in the GUI mode and
also while a user is accessing the application in Live Mode. The display name
should be given within double quotes.
• label name
It is the actual name of the field. The label name of a field is unique within a
form. Only the label name will be referred while scripting. A label name should be
alphanumeric and can contain underscore.
Sample code:
form add_employee
{
displayname = "Add Employee"
Name
Age
(
displayname = "Enter Age"
type = number
)
Date_Of_Birth
(
displayname = "Date Of Birth"
type = date
)
Qualification
(
displayname = "Educational Qualification"
type = number
)
}
where,
Name, Age, Qualification - label names
"Enter Age:" , "Educational Qualification" - display names
3. What are the different types of form fields supported in Zoho Creator?
Refer Form field - Types to learn about the lists all the field types supported by zoho
creator, its description and data type.
Renaming a field is a safe operation and would not affect the data in anyway.
• Renaming display name
Renaming the display name of a field is very straight forward. Just change the
display name in the field definition and save the script.
form add_employee
{
displayname = "Add Employee"
Name
Age
(
displayname = "Enter Age: " "Enter Employee Age: "
type = number
)
Date_Of_Birth
(
displayname = "Date Of Birth"
type = date
)
Qualification
(
displayname = "Enter Qualification" "Enter
Educational Qualification"
type = number
)
}
form add_employee
{
displayname = "Add Employee"
Name as EmpName
Age as EmpAge
(
displayname = "Enter Age:"
type = number
)
Date_Of_Birth
(
displayname = "Date Of Birth"
type = date
)
Qualification as EmpQualification
(
displayname = "Educational Qualification"
type = number
)
}
When you delete a field, all the data corresponding to the field also gets deleted and it
cannot be recovered. If no data is present, a field can be deleted by just removing the
field definition from the text area and saving the script. If data is present, Zoho Creator
will issue a error message that it is not possible to delete the field with the data present.
To delete the field in such cases, you have to explicitly use the delete keyword.
form add_employee
{
displayname = "Add Employee"
Name
delete Age
Date_Of_Birth
(
displayname = "Date Of Birth"
type = date
)
Qualification
(
displayname = "Enter Educational Qualification"
type = number
)
}
or just add a delete keyword before the field definition and save the script
form add_employee
{
displayname = "Add Employee"
Name
delete Age
(
displayname = "Enter Employee Age: "
type = number
)
Date_Of_Birth
(
displayname = "Date Of Birth"
type = date
)
Qualification
(
displayname = "Enter Educational Qualification"
type = number
)
}
6. Why is default value and tooltip not generated for some fields?
The script mode does not generate all the properties of a field. Only the properties
modified by the user will be generated back and properties still having the default values
would not get generated. e.g. For a text filed, the maxchar property will not be
generated if it has not been modified by the user.
7. Is there a way to configure a hidden field so that only the owner would be
able to view/edit it?
Yes, you can create a hidden field by having the "Hide this field to others" box checked,
as shown in the screen-shot below. Selecting this option will make this field accessible
only to the author/owner of the application.
It is possible to do it in script mode using the Hide and Show deluge keywords. Refer the
topic, Client side functions - Hide and Show for more information.
It is possible to do it in script mode by writing an on submit script for the form. The "on
submit" script gets executed before the data is persisted. In the following code, the "on
submit" script is written to find if there are rows that have the same name and data of
birth and cancels the submit action if there are any rows matching the criteria.
form user_info
{
name
(
type = text
)
dob
(
type = date
)
on submit
{
if (count(user_info[(name == input.name && dob ==
input.dob)]) > 0)
{
cancel submit;
}
}
}
Formula field
1. I have a form with a formula field. I have also created a view for it and it has
some data. I modify the formula field. But I am unable to view the table for
sometime. Why is it so ?
Whenever a formula is modified, the formula filed value will be recalculated for all the
rows. You will not be able to see the view until this recalculation is completed.
2. Can one formula field be used in another formula in the same form ?
No, using one formula field in another formula is currently not supported.
3. I'm trying to create a database for order entry. I want to have each order
stamped with the time that it was submitted at. How can I go about doing that
with ZOHO creator?
You can record the time of the entry of a record by using a formula field with it's value
set to zoho.currentime. This will automatically populate the exact time a particular
record is persisted in the database. Here's how you can do it using the Deluge script:
Time_Stamp
(
type = formula
value = zoho.currenttime
)
In the UI mode, create a field with formula as it's type and just type zoho.currenttime as
the value for the field in order to enable a timestamp.
Picklist Field
You cannot import a picklist field from one form to another form. You can only import a
textfield as a picklist in another form. (i.e) you can import a textfield in Form A as a
picklist in Form B.
Yes, you can set a picklist to display only selected records in a different table. Refer
Criteria in Import Picklist Data, for more information.
3. How can I create a dynamically populated drop down menu (single pick list).
For example if I need Country and State to be captured in a form, how do I
populate the right set of States when a Country is selected?
Yes, you can dynamically populate single picklist. Refer the topic, Add to picklist
dynamically for more information. For your example, once you obtain the country and
their corresponding state information, this is what you need to do:
• Create two picklist fields, one for country and another for state.
• For the first field, import data from the list of countries, that you already have
created.
• In the 'on change' action mode of that field, iterate through the state list for the
selected country.
• While iterating, add the selected states to the second picklist.
4. How to make a field conditionally mandatory? I have two fields (Address and
City) which are not considered mandatory unless another filed, Amount, is
greater than 100. So if Amount is greater than 100, how can I assure that
Address and City have values in them?
Yes, you can do this by adding the following code in the on submit function. In the
following code, if Amount is greater than 100 and if Address/City have no values, the
entry will not be sumitted.
on submit
cancel submit;
Date Field
You can manipulate a date field by using the '+' (to add) and '-' (to subtract) operators.
For example, if you would like to add 364 days to a particular date field, say Date1 and
display it in another field, say ExpiryDate, this is how you would do it .
Sample Code:
date1
(
type = date
)
ExpiryDate
(
type = formula
value = (date1 + '364D')
)
'D' stands for the number of days, 'W' stands for the number of weeks. The other units
of time supported are 'H' (hours), 'M' (minutes) and 'S' (seconds).
2. If I want to know the difference between two dates, how can I do it?
You can very well subtract one date from another. You will get the difference in
millisecond. You have to divide it accordingly to convert it to hours, days or weeks.
If you have the fields date2 and date1 of type date in your form, you can directly use the
above expression in a formula field
FAQ - Views
1. What are the different type of views I can create in zoho creator/deluge script ?
2. How can I rename a view in script mode ?
3. What happens to the data when I delete a view?
4. Can I have two view with same name in an application ?
5. Is it possible to create a view that takes data from multiple forms within a single
application?
6. Can I make my Form public and View private?
1. What are the different type of views I can create in Zoho creator?
The following type of views can be created in zoho creator, in both GUI and script mode.
List View
In list view, the form data will get displayed as a table. The sample code
given below creates a list view, where "View Employee" is the list name
and "add_employee" is the form name. This will display all the records in
the "add_employee" form in the form of a list.
The double quote is not needed if the view name has no special characters
other than underscore. A view name need not be unique within an
application.
Calender view
Summary view
To display only selected records in a view, refer the topic, Criteria/Filters in Views.
To rename the "View Employees" as "View All Employees", just replace the view name in
the script and save the entire script.
A view has only a display name and more than one view can have the same display
name in an application.
5. Is it possible to create a view that takes data from multiple forms within a
single application?
Yes, it is possible to create a view that takes data from multiple forms within a single
application. In ZohoCreator, relationships are established between Forms by way of
importing a field belonging to one form as picklist in another form. For example:
Now, when you create a View for an Employee, you will have the the option to select
fields both from the Employee as well the Department Form.
Yes, you can make a Form public and View private. To do this, you have to place the
Form in one tab and the View in another tab.
The validate script performs validation on the form data and is executed when a form is
submitted. The data gets persisted only if the validation does not get cancelled. Refer,
Form Actions -> Validate for more information and example.
The on success script performs an action after the form data is persisted in the database.
Refer, Form Actions -> On success for more information and example.
On update and On change are field actions performed on a specific field. These script will
be invoked only when a particular field value changes or is updated. Refer, Field Actions
for more information and example.
3. Can I script to send multiple emails? For example - send an email to all
contacts whose name is John. Is there a "for-each" command or something
similar?
Yes, you can conditionally fetch a collection of records and iterate over them. Consider
the following simple use case. The CEO of a company wants to address all the new
employees who have joined after certain date say, '10-jun-2006' . We have to mail all
these new employees. Lets see how we can achive this.
The form 'Employee' has the following fields: Name, Qualification, EmailID, TeamName,
JoinDate
2) Now iterate over the records and send the mail. Here 'x' is the instance variable that
will represent a single record in each iteration.
You can directly plug in the <br> tag into a message and zoho creator will automatically
introduce a line break. For example, when you use sendmail with the message text as
shown in the code below,
on success
{
sendmail
(
To : "xxx@adventnet.com"
From : "support@zohocreator.com"
Subject : "Welcome"
Message : "Happy <br>development <br> with Zoho Creator / Deluge"
)
}
You can create a date field and set it with the current date, using the zoho.currentdate
function inside on load action. The following deluge code will set the date field with the
current date whenever the form is loaded.
form CurrentDate
{
date1
(
type = date
)
on load
{
set date1 = zoho.currentdate;
}
}
Yes. There are two Zoho creator constants that you can use in scripting,
- zoho.loginuser
- zoho.loginuserid
It refers to the username and emailid of the currently logged in user. It would be very
useful in scripting. Refer Deluge Variables, for more information.
7. Can I find the sum of more than one numeric field in my view?
To find the sum of more than one numeric field, you can create a new field of type
"formula" as shown in the following sample code. Here, Maths, English and Science are
the fields whose sum has to be calculated. The sum value will be displayed in the
TotalMarks field.
TotalMarks
(
type = formula
value = (Maths + English + Science)
FAQ's - General
1. Why scripting ?
2. What is Deluge?
3. Do you need to know programming to be able to code in Deluge?
4. Are keywords in scripting case sensitive?
5. How do I join or relate tables with Zoho Creator! I mean, for example, if I create
a 'form' with tasks, and another one which contains labels, how can I tell ZC that
tasks are assigned one or several certain labels?
1.Why scripting ?
Deluge scripting won't be needed in case you want to build a simple data collection and
viewing application like a Contacts list. But it will be indispensable for building a full
fledged application involving some logic e.g. Library Manager.
2. What is Deluge ?
Deluge or Data Enriched Language for the Universal Grid Environment as we call it, is
the online scripting environment integrated with Zoho Creator. It shall greatly simplify
the development of collaborative web applications for managing complex data and
processes like a Bug Tracker or a Library Manager.
Definitely not. Zoho Creator primarily addresses the needs of a large number of people
who have a requirement for a web application but do not know to build it on their own.
You just need to have a clear idea about the application you want to build and how you
want it to be presented.
No the language keywords are not case insensitive but the form names and field names
are case sensitive.
5. How do I join or relate tables with Zoho Creator! I mean, for example, if I
create a 'form' with tasks, and another one which contains labels, how can I
tell ZC that tasks are assigned one or several certain labels?
To join or relate tables with Zoho Creator, you have to first create two separate forms as
given below:
1. In "Tasks" Form add a new Field say "LabelName" by using the "Import
Data From" option. There will be two options, Form-Single Select and
Form-Multi Select. Choose the option "Form-Multi Select".
2. When you choose the "Form-Multi Select" it will show a pick list with
label "Import Data From" containing the list of other Forms and their
corresponding fields in that application. Select the "Label Name" field of
the "Label" form and click "Done". This will create a relation between the
"Tasks" form and "Label" form.
3. In the Live Mode, whenever you add and entry in the "Label" form it will
automatically be available in the "Tasks" form for selection.
Sample Applications
• Overview
• Running the Application
Overview
You can create a simple bug tracking application using Zoho Creator. It has provisions
to,
• Add team members
• A form to add the team members. While adding team members, make
sure that there is only one team member with the role project tracker.
• A table to view all the team members
• File Issues
• A form to file issues
• As soon as an issue is filed, send a mail to the person to whom it is
assigned.
• Send mail to the team member to whom an issue is assigned whenever
the status is modified.
• Send mail to the project incharge if the priority of the issue in high or
v.high
• Send mail whenever the issue is reassigned to someone.
• View issues list assigned to you
• View all the issues assigned to you and are not yet closed
• View all the issues assigned to you and that are closed now
• View all pending issues
• View all the issues that are in open state
• View all the issues that are in progress
• View all issues
This bug tracker allows only one project incharge to be present. During
every form submit, the role of the new team member is checked. It more
than one team member is added as a Project Incharge, the entry is
rejected.
form team_member
{
displayname = "Add team member"
name
(
type = text
)
role
(
type = picklist
values = {Developer, Seinor Developer, QA,
Product Incharge}
)
email
(
type = email
)
on submit
{
//only one product incharge is supported by this
application
//so when a product incharge is added it checks
whether one is already present
//and if present, cancels the current entry
if ((role == "Product Incharge") &&
(count(team_member[role ==
"Product Incharge"]) > 0))
{
cancel submit;
}
}
}
File Issues
A form to file issues is created.
• As soon as an issue is filed, send a mail to the person to whom it is assigned.
• Send mail to the team member to whom an issue is assigned whenever the status
is modified.
• Also send mail to the project incharge if the priority of the issue in high or very
high.
inCharge is the nview variable and has the Users row where role is
"Product Incharge". Learn more about fetching form data.
Assigned_to
(
displayname = "Assigned to"
type = picklist
values = Users.name
on update
{
//send notification to user, if issues are
assigned to them
sendmail
[
To : this.Assigned_to.email
Subject : "Bug fixing assigned to you - "
+ this.Title
Message : this.Description
]
}
)
• Complete sample
form Issue
{
displayname = "File issue"
must have Title
(
type = text
)
Assigned_to
(
displayname = "Assigned to"
type = picklist
values = team_member.name
on update
{
//send notification to user, if issues are
assigned to them
sendmail
[
To : this.Assigned_to.email
Subject : "Bug fixing assigned to you - "
+ this.Title
Message : this.Description
]
}
on success
{
if ((this.Priority == "Very High") ||
(this.Priority == "High"))
{
//warn the product incharge of high priority
issues
inCharge = team_member [role == "Product
Incharge"];
sendmail
[
To : inCharge.email
Subject : "High Priority Issue"
Message : "Bug : " + this.Title +
"\nDescription:" + this.Description
]
}
//send notification to user, if issues are assigned
to them
sendmail
[
To : this.Assigned_to.email
Subject : "Bug fixing assigned to you - " +
this.Title
Message : this.Description
]
}
}
• Lists all the issues assigned to you that are still not closed
• Lists all the issues assigned to you that are have already been closed.
table "All_Issues"
{
show all rows from Issue
(
Title
Description
Module
Priority
Status
Reported_Date as "Reported date"
Assigned_to as "Assigned to"
)
filters
(
Module
Priority
Status
Reported_Date
Assigned_to
)
}
Recruitment
• Overview
• Running the Application
Overview
You can create a simple Recruitment application using Zoho Creator. The recruitment
application normally has two kinds of users, Applicant and the HR manager. This sample
application has provisions to do the following:
• Applicant
• Post application :An applicant posts his resume using this form
• View openings: An applicant views all the openings that are currently
available
• HR manager (Admin user of the application)
• Add new opening: A HR Manager can add new openings as per his
requirement.
• View all applications: View all the applications that have been submitted
• View shortlisted candidates: View only the applicant who have been
shortlisted by the HR Manager.
A Bug Tracker application will get created and you will be directed to the application
automatically.
form New_Applicant
{
displayname = "Add your resume"
must have Applicant_Name
(
displayname = "Your Name"
type = text
width = 30
maxchar = 30
)
must have Email_ID
(
displayname = "Email ID"
type = email
width = 30
maxchar = 30
)
Date_of_Birth
(
displayname = "Date of Birth"
type = date
)
must have Education
(
type = picklist
values = {B.E, B.Tech, B.Sc, B.Com, B.A, M.A,
M.S, M.Com, M.Sc, MBA,
MCA, M.E, M.Tech, Diploma}
)
Experience
(
type = picklist
values = {Fresher, Experience 1yr, Experience 2+yrs,
Experience 5+yrs,
Experience 10+yrs}
)
Applied_For
(
displayname = "Applied For"
type = picklist
values = New_Opening.Position_Name
)
must have Contact_Number
(
View Openings
• View all the available openings
form New_Opening
{
displayname = "Add New Opening"
must have Position_Name
(
displayname = "Position Name"
type = text
width = 30
maxchar = 30
)
must have Status
(
type = picklist
values = {Open, Closed}
)
must have Position_Type
(
displayname = "Position Type"
type = picklist
values = {Full Time, Part Time}
)
must have Experience
(
type = picklist
values = {Fresher, Experience 1yr, Experience
2+yrs, Experience 5+yrs,
Experience 10+yrs}
)
}
form shortlisted_candidates
{
displayname = "Shortlisted Candidates"
Candidate_Name
(
displayname = "Name of the candidate"
type = picklist
values = New_Applicant.Applicant_Name
)
Hiring_Manager
(
displayname = "Hiring Manager"
type = text
width = 30
maxchar = 30
)
Resume_Status
(
displayname = "Resume Status"
type = picklist
values = {Call for a Written Test, Call for an Interview,
Completed Written Test,
Being considered for the Job, Job offered,
Rejected}
on update
{
candidate = New_Applicant[Applicant_Name ==
this.Candidate_Name];
if(this.Resume_Status == "Call for a Written Test")
{
sendmail
[
To : candidate.Email_ID
Subject : "Reg application for job posted at
recruitment.zohocreator.com"
Message : "Hello " + this.Candidate_Name +
",<br><br>Please
appear for a written test to be conducted on " + this.Date_Field +
"<br> <br>
Best Regards,<br> Recruitment Manager"
]
}
else if(this.Resume_Status == "Call for an Interview")
{
sendmail
[
• Overview
• Running the Application
Overview
You can create a students marks database using Zoho Creator. It has provisions to,
• Add student information
A form is created to store all the student information.
• Update the students marks
Create a form to update the student marks and also calculate the total and
average of each of the students. Uses the formula feature in Zoho creator to
calculate total and average.
• View marksheet
Create a table to view the marksheet of the selected students
A Student marks database will get created and you will be directed to the application
automatically.
form Student_Info_Form
{
Student_ID
(
displayname = "Student ID"
type = number
)
Student_Name
(
displayname = "Student Name"
type = text
)
Date_of_Birth
(
displayname = "Date of Birth"
type = date
)
Guardian_name
(
displayname = "Guardian name"
type = text
)
Guardian_Mailid
(
displayname = "Guardian Mail ID"
type = email
)
Nationality
(
type = text
)
Date_of_Joining_the_course
(
displayname = "Date of Joining the course"
type = date
)
Form to enter the marks of all the students. This form also has two formula fields.
TotalMarks and AverageMarks. To understand more, please read about formulas.
form Students_Mark_Sheet
{
displayname = "Students Mark Sheet"
Date_of_completion
(
type = date
)
Student_Name
(
displayname = "Student Name"
type = picklist
values = Student_Info_Form.Student_Name
)
Maths
(
type = number
decimalplace = 2
)
Physics
(
type = number
decimalplace = 2
)
Chemistry
(
type = number
decimalplace = 2
)
English
(
type = number
decimalplace = 2
)
History
(
type = number
decimalplace = 2
)
Arts
(
type = number
decimalplace = 2
)
TotalMarks
(
type = formula
value = ($Maths + $Physics + $Chemistry + $English
+ $History + $Arts)
)
AverageMarks
(
type = formula
value = (($Maths + $Physics + $Chemistry + $English
+ $History + $Arts) / 6)
)
on success
{
if (((this.History < 40) || (this.Arts < 40)) ||
(this.English < 40))
{
studentInfo = Student_Info_Form [Student_Name ==
this.Student_Name];
sendmail
[
To : studentInfo.Guardian_Mailid
Subject : this.Student_Name + " Failed !"
Message : "Take proper care"
]
}
}
}