Top Banner
185

Zoho Creator Deluge Script Help Document

Oct 24, 2014

Download

Documents

Victor Savonkin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Zoho Creator Deluge Script Help Document
Page 2: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 1

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

Page 3: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 2

Debug .............................................................................................................................. 123 Alert..............................................................................................................................................124 Info ...............................................................................................................................................126

EXPRESSIONS ..................................................................................................... 128 Operators......................................................................................................................... 131 Built-In Functions ............................................................................................................. 134 Count function.................................................................................................................. 137 Count function.................................................................................................................. 137 Deluge Variables ............................................................................................................. 138

FAQ'S .................................................................................................................... 140 FAQ - Forms.................................................................................................................... 141 FAQ - Form Fields ........................................................................................................... 143 FAQ - Views..................................................................................................................... 151 FAQ's - Script Actions...................................................................................................... 154 FAQ's - General............................................................................................................... 157

SAMPLE APPLICATIONS..................................................................................... 159 Creating a Bug tracking application ................................................................................. 160

Add Team Members ....................................................................................................................161 File Issues....................................................................................................................................163 View all Issues - Assigned to You................................................................................................167 View all Issues - Pending.............................................................................................................168 View all Issues .............................................................................................................................169

Recruitment ..................................................................................................................... 170 Sample Application - Recruitment - Post Application ..................................................................171 View Openings.............................................................................................................................173 Admin - Add new opening............................................................................................................174 Admin - View Applications ...........................................................................................................175 Admin - Shortlist Candidates .......................................................................................................176

Students Marks Database ............................................................................................... 178 Students Marks Database ............................................................................................... 178

Add student info ...........................................................................................................................179 Enter student marks.....................................................................................................................181 View Student marksheet ..............................................................................................................183

Page 4: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 3

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.

Page 5: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 4

Why scripting in Zoho Creator?

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. Does it in anyway mean that you have to be a programmer ??

Page 6: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 5

Should I have programming experience to code in Deluge? Definitely not. 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.

Page 7: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 6

Getting Started with Scripting

• Creating an entire application in Deluge Script

• Adding Form and Field Action Script using Script Builder

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. Creating an entire application in Deluge Script

Refer the topic "Creating a New Application -> Deluge Script" in Zoho Creator Help Document, for more information.

Adding Form and Field Action Scripts Using Script Builder 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.

From the Forms Tab

• To add form action scripts when a new record is added, select the required form and click on More Actions -> Script (on Add). This will invoke the Script Builder in the Script tab.

• To add form action scripts when an existing record is modified, select the required form and click on More Actions -> Script (on Edit). This will invoke the Script Builder in the Script tab

Refer Form Actions for more information and examples on writing form action scripts.

• To add field action scripts when the value of a field in changed,

• Select the form and move the mouse over the required field in the form.

• Select Actions on Field Change. This will invoke the Script Builder in 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

Refer Field Actions for more information and examples on writing field action scripts.

Page 8: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 7

From the Script Tab 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.

Page 9: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 8

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.

Page 10: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 9

Using Script Builder The basic steps involved in creating a script using the script builder is given below:

Step I: Select the Form from the list 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. Step II: Select the Form/Field Action

1. To add a form action when a new entry is added, select the required Form Action. Refer Form actions, for more information.

2. To add an action when a field value is modified or updated, select the required Field Action. Refer Field Actions, for more information.

Step III: Add the deluge script 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.

Page 11: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 10

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.

Page 12: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 11

• Input fields: Input fields are the fields in the selected form. Selecting this option displays all the fields in the selected form.

• User-defined variables: Displays the custom variables, if any, defined by the user in the deluge script. Refer, Set Variable for more information.

• Zoho Variables: Displays the zoho date and string system variables. Refer Deluge System Variables, for more information.

• Collections: Displays the collection variables that holds one or more records fetched from a form.

• String Functions: Functions that operate on string expression are classified as string functions. Refer Built-in Functions - Boolean String Functions for more information.

• Date Functions: Functions that operate on date fields are classified as date functions. Refer Built-in Functions - Date Functions, for more information.

b. The list-box named b displays values based on the tab selected. For example, if the tab Input fields is selected, the content in b will display the fields in the current form. Selecting a specific field/variable/function from this list, displays the same in the text box named e. c. The text box numbered c displays information about the content displayed in list-box named b. d. The icons named d displays the arithmetic and relational operators. Click on the required operator to add it to the text box named e. Selecting a Refer Operators, for more information. e. The text box named e displays the condition created.

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.

Page 13: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 12

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

Page 14: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 13

Form Actions - On Load

• 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 } }

Page 15: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 14

Examples - Free flow scripting 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; } } }

2. Hide fields while loading a form on edit The on load action script in the following example, will be executed when the user edits an existing record. The script will hide the fields Name and Email_id in the form, and allow only the other field values to be edited by the applicant.

form ApplicationForm { Name ( type = text ) EmailId ( type = email )

DateOfBirth

Page 16: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 15

( 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; } } }

Page 17: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 16

3. Set default value for fields on add You can set default value for fields including picklist while loading a form. The following script will set the value "Available" to the form field "Status".

on add { on load { set Status = "Available"; } }

Example - Using Script Builder Refer the topic, Client Side Function - Set Field - Example Using Script Builder.

Page 18: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 17

Form Actions - Validate

• 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.

Page 19: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 18

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; } } }

Examples - Free Flow Scripting

• To validate if a field value falls within a specified range - on add/on edit

• To check for duplication of records - on add

• To restrict registrations - on add

• To update the value of a field based on the values in other fields - on add/on edit

To validate if a field value falls within a specified range - on add / on edit 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.

Page 20: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 19

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; } } }

To check for duplication of records - on add 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, team_member [name == input.name] - selects all the team_members whose name is equal to the name currently entered. input.name - it is the value for the field "name" given by the user while submitting the form count - count operator returns the number of team members whose name is equal to this.name

Page 21: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 20

To restrict registrations to your application - on add

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; } } }

The following deluge code, uses the zoho.currentdate function to validate if the registration date has expired.

on add { on validate { if (zoho.currentdate > '20-Mar-2007') { alert "time for registration expired"; cancel submit; } } }

To update the value of a field based on the values in other fields - on add/ on edit 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; } }

Page 22: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 21

on edit { on validate { input.PatientID = input.First_Name + " " + input.Last_Name + " " + zoho.currenttime; } }

Example - Using Script Builder Refer the example in the topic, Statements -> Control Statements -> Cancel Submit. Related Links:

• FAQ's - Form Actions • Alert • Cancel Submit

Page 23: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 22

Form Actions - On Success

• Description

• Syntax

• Example - Free Flow scripting

• Example - Using Script Builder

• Related Links

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. By default, the message "Data Added Successfully" is displayed on successful submisson of form data. You can customize the success message by specifying the same in the success message string. Refer On success message for more information. Syntax

On success action script - On add : The on success action script written inside the On Add block is invoked when a new record is added to the database.

on add { on success { // write deluge script to be executed when a new form data is persisted in the database } }

On success action script - On edit : The on success action script written inside the On Edit block is invoked when an existing record is updated and persisted in the database.

on edit { on success { //write deluge script to be executed when a new form data is persisted in the database } }

Page 24: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 23

Example - Free Flow Scripting

Send Mail : In the below given feedback form sample, a mail is sent when a new form data is persisted in the database.

application "Feedback Application" { page "Feedback Application Home" { form Send_Feedback { displayname = "Send Feedback" 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

Page 25: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 24

) 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.

Example - Using Script Builder Refer the topic, Miscellaneous -> Success Message. Related Links

• FAQ's - Form Actions • On success message

Page 26: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 25

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:

On User Input: On User input is a client side action, which will be invoked whenever you change the value of a field in the form. On Update: If you want to perform action whenever the value of a field gets modified, you can write an on update script for that field. It is a server side event, and the field action will be executed only after you have saved the changes to the database (after you click the 'Update' button in the form)

Page 27: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 26

Field Actions - On User Input

• 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.

Page 28: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 27

Deluge code snippet:

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.

Example - Using Script Builder

Refer the Example - Using Script Builder in the topic,Client Side Functions -> Clear Picklist.

Page 29: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 28

Field Actions - On update

• 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:

• The on update action is field specific. • The action will be executed only after you have saved the changes

to the database.

Syntax

on update { // specify deluge code to be executed }

Example - Free Flow Scripting 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

Page 30: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 29

Improvement", "Bug Report", "Usability"} ) 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; } } } }

Example - Using Script Builder 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

Page 31: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 30

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>

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. b. Click on Edit to specify the If condition.

o 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.

Page 32: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 31

3. Sendmail: Now, we have to add the If statements to be executed, when the If condition is satisfied. In our example, if the value of status is "Closed", an email is sent to the sender with the comments.

a. To add the sendmail function, drag and drop Miscellaneous -> Sendmail, to the editor area. Click on Edit to specify the From, To, Subject and Message for Send mail.

Page 33: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 32

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.

c. The sendmail is added to the script editor. Click on Save Script to update the changes.

Page 34: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 33

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.

Page 35: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 34

Filters

• Specifying Criteria in Views

• Specifying Criteria in Import Picklist

Page 36: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 35

Criteria / Filters in Views

• 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

list <"View Name"> { show all rows from < Form Name > ( < Field name > < Field name > < Field name > < Field name > ) 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"]

Page 37: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 36

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".

• user defined or import data single select • user defined or import data multiple select • date

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 )

Page 38: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 37

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.

Page 39: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 38

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.

Page 40: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 39

Criteria in Import Picklist Data

• 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:

Page 41: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 40

Deluge code:

form FormB { IndianStates ( type = picklist values = FormA[Country == "India"].State ) }

where the expression, 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

• Add to Picklist Dynamically • Clear Picklist

Page 42: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 41

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.

Page 43: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 42

Complete Sample

application "Student marks database" { page "Enter marks" { form Students_Mark_Sheet { displayname = "Students Mark Sheet" Student_Name ( displayname = "Student Name" type = text ) English ( type = number decimalplace = 2 ) Arts ( type = number decimalplace = 2 ) TotalMarks ( type = formula value = English + Arts ) AverageMarks ( type = formula value = (English + Arts) / 2 ) } list "View student marks" { Students_Mark_Sheet } } }

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).

Also refer FAQ -> Form Fields -> Formula fields.

Page 44: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 43

Statements

Deluge Statements

• Control Statements

• Data Access

• Client Side Functions

• Miscellaneous

• Debug

Page 45: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 44

Control Statements

• if, else if, else

• Iterator - for each record in form

• Iterator - for each value in list

• Cancel Submit

• Set Variable

Page 46: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 45

Conditional Execution - If, else if, else

• 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> }

An If construct should adhere to the following rules:

• It should have an 'If' condition

• It can have zero or more 'else if' conditions

• It can have an optional 'else' part

When an <If Construct> is encountered during script execution, the condition specified by the <if-boolean_expression> is evaluated. If the condition is met, the statement in the <if statements> block are

Page 47: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 46

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. When an else if part is encountered, the condition specified by <boolean_expression-x> is evaluated and if the condition evaluates to true, the statements in <elseif statements-x> block is executed. If the <if condition> and all the <else if conditions> fails then the presence of <else> is searched and the statements in <else statements> block is executed.

Example - Free flow scripting 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, "[email protected]" 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 : "[email protected]" Subject : "Applicants resume matches job profile" Message : this.Applicant_Name + " matches the job profile <br> Contach Info: " + this.Email_ID ] } else { sendmail [

Page 48: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 47

"[email protected]" 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 Example - Using Script Builder Refer the topic Statements -> Control Statements -> Cancel Submit to built a Validate action script with If construct, Alert and Cancel submit.

Page 49: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 48

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:

for each <row-variable> in <formname> [criteria]

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:

for each <row-variable> in <formvariable>

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.

Page 50: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 49

Example

Visualize a simple HR application. The form 'Employee' has the following fields.

o Name - Name of the Employee

o Qualification - Employee Qualification

o JoinDate - Date of joining the company

o Email - Official email id of the employee

o Team - Team name of the employee

We want to send emails individually to each member of a product team say, 'Deluge' team.

sample 1:

for each x in Employee [Team == "Deluge"] { sendmail ( To : x.Email Subject : "Important announcement" Message : "Your message goes here" ) }

where,

o x : row variable

sample 2:

employeerecords = Employee [Team == "Deluge"]; for each x in employeerecords { sendmail ( To : x.Email Subject : "Important announcement" Message : "Your message goes here" ) }

where,

o x : row variable

o employeerecords : It contains the form data

Example : Using Script Builder 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.

Page 51: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 50

Iterate Multiple Picklist Values (for each list value)

• 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

for each <fieldname> <variable> in <formname/rowvariable> [criteria]

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.

Example - Free Flow Scripting Visualize a simple Sports Registration application. It has two forms.

1. The form Sport_Coaching_Details has the following fields.

• Sport_Name - Name of the sport for which coaching is offered.

• Minimum_Age - Minimum age required for the sport.

• Maximum_Age - Maximum age limit for each sport.

• Fees - The fees collected for coaching.

Page 52: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 51

2. The form Sports_Registration has the following fields.

• 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

Page 53: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 52

Sport_Coaching_Details. If so, an email is sent with the message that the registration for that sport is accepted. The following code in the on success event block does this. Deluge code snippet

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.

Page 54: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 53

Deluge code explanation 1. Checks whether the total registration is greater than or equal to 15. Here, Sports_Registration is the name of the form.

if (count(Sports_Registration) >= 15)

2. Iterates through each row in the Sports_Registration form. Here, r is the name of the row variable that contains the data for a single record corresponding to each iteration.

for each r in Sports_Registration

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.

for each Sports x in r

4. Checks whether the Age specified in the Sports_Registration form, is within the Minimum_Age and Maximum_Age limit specified for this sport in the Sports_Coaching_Details form. - r.Age fetches the Age value from the row variable r in Sports_Registration form. - x.Minimum_age will fetch the Minimum_age for this Sport from the Sports_Coaching_Details form.

if ((r.Age > x.Minimum_Age) && (r.Age < x.Maximum_Age))

5. The sendmail function is called to send an email to the Emailid specifed in row r.

sendmail ( To : r.Emailid Subject : "Registration for Sports coaching from " + r.Name Message : "Your registration for" + x.Sport_Name + "is accepted" )

Page 55: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 54

Example : Using Script Builder 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 the form Sports_Registration from the list of forms displayed in the top left corner of the script editor. b. Select Form Actions -> On Success. Sample form actions will be displayed in the editor area. Delete the sample statements.

2. for each record

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.

Page 56: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 55

• Since we want to iterate through all the records, we do not specify any criteria.

• Click Done to add the script in script editor.

The deluge statement to iterate each row r in the form "Sports_Registration" is added to the script editor, as shown below:

Page 57: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 56

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.

Note: When a formvariable/collectionvariable is selected instead of formname, the dialog does not display the criteria text box.

Page 58: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 57

The deluge for each list value is added to the script editor, as shown below:

3. If condition: a. Drag and drop the If control flow statement, as highlighted in the screen-shot below. Click on Edit to specify the 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.

Page 59: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 58

• Select the Collections Tab to display the collecton variables. Select the variable r from the Variables list . Here, r contains the data for a single record corresponding to each iteration in Sports_Registration.

• Click on the Age field from the list of fields in the variable r. The condition r.Age will be added to the text area below.

• Add the > operator from the list of operators.

• 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.

Page 60: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 59

• Click Done to add the If condition to the script editor.

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.

Page 61: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 60

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.

Page 62: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 61

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.

Page 63: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 62

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.

Examples - Free flow Scripting

1. Alerts the message specified in quotes and cancels submission, if the value entered in the age field is not between 20 and 100.

Age ( type = number ) on submit { if (input.Age < 20) && (input.Age >100) { alert "age should be between 20 to 100"; cancel submit;

Page 64: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 63

} }

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; } }

Example - Using Script Editor 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.

• Add Validate Action o If <condition> o Alert o Cancel submit

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>

a. Drag and drop the If control flow statement, as highlighted in the screen-shot below. Click on Edit to specify the If condition. Refer the If, else if, else topic, for more information on the syntax and usage.

Page 65: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 64

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.

Page 66: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 65

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.

Page 67: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 66

4. Add Cancel Submit: To cancel submission,

• 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.

Page 68: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 67

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.

Page 69: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 68

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.

Page 70: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 69

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";

Page 71: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 70

} 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.

total = (input.English + input.Maths);

2. The following code sets a user defined variable total as the value of the variable average.

total = (input.English + input.Maths); average = (total / 2);

3. The following example sets a zoho variable, zoho.currenttime to the variable name datex.

datex = zoho.currenttime;

4. The following example sets a date value to the variable dd.

dd = '12-Apr-2007';

Page 72: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 71

Data Access

• Fetch Records

• Modify Records

Page 73: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 72

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. To access the currently submitted/persisted field values, deluge automatically initializes and passes on a variable named input to your onsuccess and onchange functions. You have to use the passed on variables 'input' to access the currently submitted/persisted field values. 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

Page 74: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 73

) }

• 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 ] } ) }

If the status of an issue gets modified, an email is to be sent to the team member to whom the issue is assigned with the issue description.

Page 75: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 74

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'. tm = team_member [name == input.assigned_to]; 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. tm.mailid - mailid of the team member input.status - status of the issue input.description - description of the issue

Note: The fields in a form are referred to as columns in an nview. All the columns in an nview have to be referred using input keyword as deluge automatically initializes an nview variable named 'input'.

Example - Using Script Buider Refer the topic, Data Access -> Modify Records -> Example Using Script builder.

Page 76: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 75

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

Example: Consider a Library manager application Take a very simple use case : User is borrowing a book from the library. In library manager terminology, it is called 'Issuing a Book'.

Page 77: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 76

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.

In addition to getting book and user information, we need to do the following

• Store the current date in the 'issue date' field(hidden from user) of the above form, indicating that the book is issued today.

• Change the status of this book from 'Available' to 'Issued'.(This data is available in different form i.e Book form)

Page 78: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 77

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"; //store the current time in 'issue date' field. issuedate = zoho.currenttime; }

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).

Page 79: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 78

Example - Using Script Buider Let us add the on success script for the Library Manager application - Issue Book Form, using script builder.

• Add Form Actions - On Success • Fetch Records • Update Records • Set Variable

Add "Form Actions - On Success"

a. Click on the Script Tab to display the Script Editor.

b. Select the form Issue_Book from the Select listbox.

c. Select the Form Action On Add -> On Success as highlighted in the

screen-shot below.

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:

Page 80: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 79

b. Select Edit option to specify the variable name, formname and criteria

to fetch the records.

c. 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 Books.

• Specify the collection variable name as any user defined name to

store the fetched records. Here we specify the name as myBook.

• Specify the criteria based on which the data is to be fetched from

the Books form. In our example, we have to fetch the records from

Books whose name is same as the name of the book(input) in the

Issue_Book form. To do this,

• Select the tab Criteria fields. This will display all the fields in the

Books form.

• Double-click on Name to add it to the value textbox.

• Select the == symbol to add it to the value textbox.

Page 81: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 80

• Select Input fields in the Variables listbox to display fields available in the input form. I

• Double-click on Nameofthebook from the list. You will now find the syntax input.Nameofthebook added in the text area.

• Click Done to add the syntax to the text editor.

Page 82: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 81

The deluge syntax to fetch the records is added to the script editor, as shown below:

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.

Page 83: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 82

c. The Update records dialog will be displayed as shown in the screen-shot given below:

• Specify the row variable name myBook, that contains the fetched record.

• Select the field name in myBook whose data has to be updated with the specified value.

• Specify the value to be updated as "Issued" in the text area.

• Click Done to add the syntax to the text editor.

The deluge syntax to update the record is added to the script editor, as shown below:

Set Variable: To set the Date field in the Issue_Book form with the current date,

Page 84: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 83

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: b. Select Edit option to specify the variable name and value.

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.

Page 85: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 84

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.

Page 86: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 85

View Form: 1. 'Status' of the book 'The City of Joy' is modified.

2. Current date is automatcally stored in the 'Issue date' field

Page 87: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 86

Client Side Functions The following client side functions can be used inside the On Load form action and On change field action scripts:

• Hide/Show

• Set Field

• Add to picklist dynamically

• Clear Picklist

• Alert Box

Page 88: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 87

Client Side Function - Hide and Show

• 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

hide <field name>; show <field name>;

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; }

Page 89: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 88

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; } } )

Page 90: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 89

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!”; } }

Page 91: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 90

Client Side Function - Set Field

• 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

set <field name> = <value>;

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; } }

2. To set default value for a field of type radiobutton in the on load form action.

form Data { must have Grade ( type = radiobuttons values = {"Good", "Better", "Best"} )

on load

Page 92: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 91

{ set Grade = "Better"; } }

3. To set the value of a field in the on load form action, based on a condition.

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!”; } }

Example - Using Script Builder 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. Add "On Load" Form Action Add "Set Field" View Script View Form 1. Add On Load form action: Select the Form Actions -> On Add -> On Load as highlighted in the screen-shot below. 2. Add Set field:

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.

Page 93: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 92

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.

Page 94: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 93

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.

Page 95: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 94

View SampleForm1 When the SampleForm1 is loaded, the Date1 field is set with the current date as shown below.

Page 96: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 95

Client Side Function - Add to Picklist Dynamically

• 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);

Example - Free Flow Scripting 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. Example - Using Script Editor 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:

• Criteria in Import Picklist • Clear Picklist

Page 97: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 96

Client Side Function - Clear Picklist

• Description

• Syntax

• Example - Free Flow Scripting

• Examples - Using Script Editor

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

clear <single select list fieldname>

Example - Free Flow Scripting Let us take a Bug Tracker application as an example. It has three forms.

1. Form to fill in the module names. e.g. In the case of Zoho Creator, it could be user interface design, deluge script etc. See a list view of all the modules added.

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

Page 98: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 97

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.

If ‘Persistence’ is selected in the ‘Module’ picklist, only those members of the team, in charge of the ‘Persistence’ module should get listed in the ‘Assigned to’ picklist. In this example, Edward and John should get listed. In the following script, we have added an if condition to the same example to check if the module selected has one or more team members. If the module does not have any team members, the Assigned_to picklist field will be cleared. The following deluge code does this.

form FileIssue { Title ( type = text ) Description ( type = textarea ) Module

Page 99: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 98

( 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)

Page 100: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 99

{ clear AssignedTo; }

2. If statement: If the count is 0, (i.e) no records in TeamMember form with the selected Module name, the AssignedTo picklist field will be cleared. If the count is more than 0, the else statements will be executed.

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); } }

Since the variable team is an array, it has to be iterated to get the properties of each team member.

for each t in team { Assigned_to.add(t.name); }

The names of those team members in charge of the ‘Persistence’ module are added to the ‘Assigned to’ picklist.

for each t in team { Assigned_to.add(t.name); }

Page 101: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 100

Example - Using Script Editor 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. b. Click on Edit to specify the If condition.

c. The Edit dialog for If is displayed as shown below, wherein you have to create the If condition.

Page 102: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 101

Note: Count function is currently not supported in script editor. Hence, you have to manually specify the condition with the count function as shown below. Refer the topic, Count function for more information.

d. Click Done to add the If condition to the script editor.

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.

Page 103: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 102

a. To clear a picklist field, drag and drop Client Functions -> Clear Picklist. b. Click on Edit to specify the picklist fieldname.

c. Click Done to add the field name to the script editor.

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:

Page 104: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 103

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.

Page 105: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 104

• 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.

Page 106: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 105

The deluge syntax to fetch the records is added to the script editor, as shown below:

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.

Page 107: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 106

b. The for each record dialog is displayed as shown below:

• Select the collection variable team from the list. This variable stores the records fetched from the TeamMember form.

• Specify the rowvariable as any userdefined name. Here, we will specify the rowvariable as t.

Note: In our example, we have already fetched the records from teammember form and stored in a variable named team. So we will specify this collection variable team, instead of formname[criteria]. When a collection variable is selected instead of formname, the dialog does not display the criteria text box.

c. Click Done to add the for each syntax to the script editor.

The deluge for statement to iterate each row t in the formvariable team is added to the script editor, as shown below:

5. Add to Picklist: For each row t in the formvariable team, we have to add the Name to the Assignedto picklist field.

Page 108: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 107

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.

b. The Add to Picklist dialog is displayed as shown below.

• The Select picklist name listbox will display all the picklist fields in the current FileIssue form. Select AssignedTo picklist from the list of picklists displayed.

• Select the collection variable t from the variables list and click on the Name field.

• You will now find the syntax t.Name added in the text area.

• Click Done to add the syntax to the text editor.

Page 109: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 108

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.

Page 110: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 109

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.

Page 111: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 110

Client Side Function - Alert Box

• Overview

• Syntax

• Examples

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"); } ) }

Page 112: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 111

Miscellaneous

• Send mail

• On success message

Page 113: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 112

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 : "[email protected]" subject : "Welcome" message : "Happy development with deluge zoho creator" ]

Example - Using Script Builder Refer the Example Using Script Builder in the topic, On Success Message.

Page 114: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 113

Success Message

• Overview

• Syntax

• Example - Free flow scripting

• Example - Using Script Builder

Overview The on success message is displayed on successful submisson of form data. By default, the message "Data Added Successfully" is displayed. If you want to customize this message, you have to specify the same in the success message string as shown below. Syntax

on add { on success { //specify the message here success message ""; } }

Example - Free flow scripting

on add { on success { success message "employee record added"; } }

Example - Using Script Builder 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.

Page 115: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 114

• Add Form Actions - On Success • Add Send Mail • Add Success Message • View Script • View Form

Add "Form Actions - On Success"

a. Click on the Script Tab to display the Script Editor. b. Select the form Send_Feedback from the Select listbox. c. Select the Form Action On Add -> On Success as highlighted in the screen-shot below.

Add "Send mail"

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:

Page 116: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 115

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.

Page 117: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 116

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.

Page 118: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 117

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.

Page 119: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 118

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.

Page 120: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 119

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.

View Feedback Form 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.

Page 121: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 120

The success message specified in the script is displayed as shown in the screen-shot below:

Page 122: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 121

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>

Example - Free flow Scripting 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; } }

Page 123: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 122

Example - Using Script builder 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.

Page 124: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 123

Debug

• Alert

• Info

Page 125: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 124

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.

Examples - Free Flow Scripting

1. Alerts the message specified in quotes and cancels submission, if the value entered in the age field is not between 20 and 100.

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

Page 126: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 125

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; } }

Example - Using Script Builder Refer the topic Statements -> Control Statements -> Cancel Submit to built a Validate action script with If construct, Alert and Cancel submit.

Page 127: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 126

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 : "[email protected]" Subject : "Report for Product Status: " + input.Product_Status_is Message : "Product: " + productno ) } info "Report has been sent."; } }

Page 128: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 127

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; }

Page 129: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 128

Expressions

• Expression types

• Variables

• Literals or Constants

An expression is a combination of variables, constants and operators that on evaluation yields a single value. Expression types Expression in deluge are classified as follows:

• String Expression

• Numeric Expression

• DateTime Expression

• Boolean Expression

String Expression A string expression evaluates to a sequence of characters or text. For example: "abcd" , "zoho " + "creator " + " - online"

sendmail [ To : this.name+"@adventnet.com" Subject : "The feedback you had sent has been incorporated in zohocreator" Message : "Comments" + this.comments ]

In the above sample, - comments and name are the fields of the form. - name+"@adventnet.com" is a string expression. - "Comments " + this.comments is also a string expression. Numeric Expression A numeric expression evaluates to number, either floating point (e.g. 4.556 or -5.311) or integer numbers (e.g. -41 , 6243).

English ( type = number decimalplace = 2 )

Page 130: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 129

Arts ( type = number decimalplace = 2 ) AverageMarks ( type = formula value = (English + Arts) / 2 )

In the above sample, (English + Arts) / 2 is a numeric expression 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') )

In the above sample, Date_Of_Joining is a date type field 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 Refer the topic, Set Variable for more information.

Page 131: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 130

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 ]

In the above sample, "[email protected]" is a string constant.

Page 132: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 131

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 It operates on two values and hence called binary arithmetic operators Syntax <op1> <Operator> <op2> 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

+ functionality wise, it has no effect

- negates the given value

Page 133: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 132

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 5 > 4 -> true 233.6 < 94.22 -> false Syntax <op1> <Operator> <op2> The table below lists the binary arithmetic operators and their functionality:

Operator Functionality > <op1> is greater than <op2> >= <op1> is greater than or equal to <op2> < <op1> is less than <op2>

<= <op1> is less than or equal to <op2> == <op1> is equal to <op2> != <op1> is not equal to <op2>

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 <boolean expression> && <boolean expression> <boolean expression> || <boolean expression> ! <boolean expression> 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

&& Both the left and right boolean expressions are true

ll Atleast one of the boolean expression is true ! boolean expression is false

Page 134: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 133

Datetime operators: The Datetime operators are used to manipulate date values. 1. Adding a delta time period to date Syntax <datetime expression> <Operator> <delta value> where, - A <datetime expression> is a fixed date and time in calendar. - 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 1 week and 80 minutes can be written as '1W:80M' 2 days, 40 minutes and 30 sec can be written as '2D:40M:30S' Also refer FAQ -> Form Fields -> Date fields.

Page 135: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 134

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.

Operator Functionality** Concatenate two strings

+ <string1> + <string2> Concatenate two strings

remove(<string>) <string>.remove(<substring>)

Eliminate the substring from the given string.

removeFirstOccurence() <string>.removeFirstOccurence(<substring>)

Eliminate the first occurence of the substring from the given string.

removeLastOccurence() <string>.removeLastOccurence(<substring>)

Eliminate the last occurence of the substring from the given string.

getSuffix() <string>.getSuffix(<substring>)

Get the string after the specified substring.

getPrefix() <string>.getPrefix(<substring>)

Get the string before the specified substring.

toUpperCase() <string>.toUpperCase()

Convert the string to uppercase.

toLowerCase() <string>.toLowerCase() Convert the string to lowercase.

Page 136: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 135

Operator Functionality** Concatenate two strings

getAlphaNumeric() <string>.getAlphaNumeric()

Retain only the alphanumeric present in the specified string.

getAlpha() <string>.getAlpha()

Retain only the alphabets present in the specified string.

removeAllAlphaNumeric() <string>.removeAllAlphaNumeric()

Remove all the alphanumeric present in the specified string.

removeAllAlpha() <string>.removeAllAlpha()

Remove all the alphabets present in the specified string.

length() <string>.length() Get the length of the given string.

getOccurenceCount() <string>.getOccurenceCount(<substring>)

Gets the number of times a substring is present in the given string.

indexOf() <string>.indexOf(<substring>)

Gets the index of the first occurence of the substring in the given string.

lastIndexOf() <string>.lastIndexOf(<substring>)

Gets the index of the last occurence of the substring in the given string.

** <string>,<string1>,<string2>, <substring> are all <string expression>

Page 137: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 136

Boolean string functions These functions operate on two string expression and return a boolean expression.

Operator Usage Returns true when

== <string1> == <string2> two string expressions are equal

contains() <string1>.contains(<string2>) string2 is a substring of string1 startsWith() <string1>.startsWith(<string2>) string1 starts with string2 endsWith() <string1>.endsWith(<string2>) string1 ends with string2

Date functions

Operator Usage Returns

getDay() <date>.getDay() where, <date> is a form field of type "date"

returns a number in the range (1 - 31), representing the number of the day of the month on which the date occurs.

getMonth() <date>.getMonth() where, <date> is a form field of type "date"

returns a number in the range (1 -12), representing the number of the month of the year, on which the date occurs.

getYear()

<date>.getYear()

where, <date> is a form field of type "date"

returns a number representing the year of the date.

getWeekOfYear()

<date>.getWeekOfYear()

where, <date> is a form field of type "date"

returns a number in the range (1 - 52), representing the number of the week in the year.

For example, "16/1/2007" returns 3.

getDayOfWeek()

<date>.getDayOfWeek()

where, <date> is a form field of type "date"

returns a number in the range (1 - 7), representing the numberof the day of the week, that datefalls.

The number "1" represents Sunday, "2" represents Monday and so on.

Page 138: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 137

Count function

• Description • Syntax • Examples

Description The count operator returns the number of rows in a form/formvariable. 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, team_member - is the name of the form. team_member [name == input.name] - selects all the team_members whose name is equal to the name currently entered in the name field. input.name - it is the value for the field "name" given by the user while submitting the form count - count operator returns the number of team members whose name is equal to input.name 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, Employee - is the name of the form count - count operator returns the number of records in the Employee form.

Page 139: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 138

Deluge Variables

• Date Variables

• String Variables

• Examples

Date Variables

1. To get the current date

zoho.currentdate()

2. To get the current time

zoho.currenttime()

String Variables

1. Returns the the user name of the currently logged-in user.

zoho.loginuser()

2. Returns the emailid of the currently logged-in user.

zoho.loginuserid()

3. Returns the name of the application owner.

zoho.adminuser()

4. Returns the emailid of the application owner.

zoho.adminuserid()

Page 140: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 139

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.

list "My Leave Details"s { 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: [Employee_email == zoho.loginuserid] - The filter to display only the leave details of the current user where, 'Employee_email' is a field in the form emp_leave_form 'zoho.emaild' is the deluge variable.

Page 141: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 140

FAQ's

• Forms • Form Fields • Views • Script Actions • General

Page 142: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 141

FAQ - Forms

1. How do you define a form in deluge?

2. How do you rename a form in deluge?

3. How do you delete a form?

4. Can I have two forms with same name in an application ?

1. How do you define a form in deluge? 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, add_employee - label name "Add Employee" - display name

2. Is is possible to rename a form in script mode ? Renaming a form is a safe operation and would not affect the data in anyway.

Rename display name 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" }

Page 143: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 142

Rename label name The label name can be renamed by using the following syntax.

form add_employee as add_new_employee { displayname = "Add New Employee" }

Just replacing add_employee as add_new_employee is equivalent to deleting the form add_employee and creating a new form add_new_employee.

3. How do I delete a form with data (script mode) ? 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,

delete form add_employee

or just add a delete keyword before the form definition, as shown below.

delete form add_employee { displayname = "display name of the form" }

Note: When you delete a form, all the data corresponding to the form also gets deleted and it cannot be recovered.

4. Can I have two forms with same name in an application ? 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.

Page 144: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 143

FAQ - Form Fields

• General • Formula field • Picklist field • Date field

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

1. Can I import picklist from another form?

2. Can I set a picklist to display only selected records in a different table?

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?

Date Field

1. How can I calculate a date from another date field?

2. If I want to know the difference between two dates, how can I do it?

Page 145: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 144

General 1. How do I define form fields in deluge? 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

Note: If no type is specified, it is assumed to be of type text field. e.g. Name

2. Is there any naming conventions to be followed while defining form fields? A fieldname should be alphanumeric and can contain underscore. 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.

Page 146: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 145

4. How do I rename form fields in script mode? 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 ) }

• Renaming label name

The label name can be renamed by using the following syntax.

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 ) }

Page 147: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 146

5. Can I delete a form field that contains data ? If so, how? 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. See a sample error message below:

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"

Page 148: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 147

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.

Page 149: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 148

8. Is it possible to hide/display a field based on a condition? 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. 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 ? 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.

Page 150: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 149

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 1. Can I import a picklist field from form A to form B? 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. 2. Can I set a picklist to display only selected records in a different table? 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.

Page 151: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 150

on submit { if ((input.Amount > 100) && ((input.Address == "") || (input.City == ""))) { alert "enter Address/City"; cancel submit; } }

Date Field 1. How can I calculate a date from another 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. get difference in days = (date2 - date1) / (1000 * 60 * 60 * 24) 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

Page 152: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 151

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.

list "View Employees" { add_employee }

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 In calender view, the data will be presented as a calender. This view is supported only if there is a date column.

calendar "View Employees" { add_employee }

Page 153: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 152

Summary view A summary view gives more information than a table/list view. But it is not possible to see any pattern in a summary view like in table view. This will display all the records in the "add_employee" form in the form of a summary.

summary "View Employees" { add_employee }

To display only selected records in a view, refer the topic, Criteria/Filters in Views. 2. How can I rename a view in script mode? To rename the "View Employees" as "View All Employees", just replace the view name in the script and save the entire script.

calendar "View Employees" "View All Employees"{ show all rows from add_employee ( Name Age Date_Of_Birth Qualification ) }

3. What happens to the data when I delete a view ? The data remains unaffected if a view is deleted. 4. Can I have two views with same name in an application ? 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: - Form "Department" has fields Name, DepartmentHead and Location. - Form "Employee" has fields Name, Age, Address and DepartmentName, where DepartmentName is an imported field from the "Name" field in "Department" Form. This way a relationship is established between Department and Employee. 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.

Page 154: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 153

6. Can I make my Form public and View private? 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.

Page 155: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 154

FAQ's - Script Actions

1. What is the difference between on-validate and on-success script?

2. What is the difference between on-update and on-change script?

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?

4. How do you put a line break in the message during a "sendmail"?

5. Can I display todays date in my form when the form is opened/loaded?

6. Can I obtain my emailid and username for use in scripting ?

7. How do I add a SUM function into my script?

1. What is the difference between on-validate and on-success script? 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. 2. What is the difference between on-update and on-change script? 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 1) Fetch the data by applying filter. emprecords = Employee [JoinDate > '10-Jul-2006']; 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.

Page 156: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 155

for each x in emprecords { sendmail ( To : x.EmailID From : "[email protected]" Subject : "Meeting" Message : "You are requested to attend the meeting at 6:pm tomorrow" ) }

4. How do you put a line break in the message during a "sendmail"? 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 : "[email protected]" From : "[email protected]" Subject : "Welcome" Message : "Happy <br>development <br> with Zoho Creator / Deluge" ) }

the message will be displayed like this:

Happy development with Zoho Creator / Deluge

5. Can I display todays date in my form when the form is opened/loaded? 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 )

Page 157: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 156

on load { set date1 = zoho.currentdate; } }

6. Can I obtain my emailid and username for use in scripting ? 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)

Page 158: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 157

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. 3. Do you need to know programming to be able to code in Deluge? 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.

4. Are keywords in scripting case sensitive ? 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. Create a form "Tasks" with a field "Task Name". 2. Create another form "Label" with a field "Label Name".

Page 159: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 158

To relate the two forms :

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.

Page 160: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 159

Sample Applications

• Bug Tracker Application

• Recruitment Application

• Students Marks Database Application

Page 161: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 160

Creating a Bug tracking application

• 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

Running the Bug Tracker Application Steps to run the application:

• Go to http://www.zohocreator.com and login

• Click on Create Application and select the tab Import script.

• Just copy and paste the code in the textarea available and click on Create button. A Bug Tracker application will get created and you will be directed to the application automatically. View the complete script here - bug_tracker.ds

Page 162: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 161

Add Team Members • Form to add the team members

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; } } }

Page 163: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 162

• A table view is created to view all the team members.

list "List Team" { show all rows from team_members ( name role email ) filters ( role ) }

Page 164: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 163

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 notification to user, if issues are assigned to them sendmail [ To : input.Assigned_to.email Subject : "Bug fixing assigned to you - " + input.Title Message : input.Description ]

• Send mail to the team member to whom an issue is assigned whenever the status is modified.

must have Status ( type = picklist values = {Open, InProgress, Closed} on update { if ((input.Status == "Closed") && ((input.Priority == "Very High") || (input.Priority == "High"))) { //email the product incharge of closed high priority issues inCharge = Users [role == "Product Incharge"]; sendmail [ To : inCharge.email Subject : "Bug Closed" Message : "Bug with the title - " + input.Title + " is closed" ] } } )

• 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.

Page 165: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 164

if ((this.Priority == "Very High") || (this.Priority == "High")) { //warn the product incharge of high priority issues inCharge = Users [role == "Product Incharge"]; sendmail [ To : inCharge.email Subject : "High Priority Issue" Message : "Bug : " + this.Title + "\nDescription:" + this.Description ] }

• Also send mail whenever the issue is reassigned.

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 ) must have Description ( type = textarea )

Page 166: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 165

must have Module ( type = picklist values = {Persistence, Xml, Usability} ) must have Priority ( type = radiobuttons values = {Very High, High, Medium, Low} ) must have Status ( type = picklist values = {Open, InProgress, Closed} on update { if ((this.Status == "Closed") && ((this.Priority == "Very High") || (this.Priority == "High"))) { //email the product incharge of closed high priority issues inCharge = team_member [role == "Product Incharge"]; sendmail [ To : inCharge.email Subject : "Bug Closed" Message : "Bug with the title - " + this.Title + " is closed" ] } } ) Reported_Date ( displayname = "Reported date" type = date ) 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 ]

}

Page 167: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 166

) 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 ] } }

Page 168: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 167

View all Issues - Assigned to You

• Lists all the issues assigned to you that are still not closed

list "Pending issues" { show all rows from Issue [(Status != "Closed" && Assigned_to.email == zoho.loginuserid)] ( Title Description Module Priority Status Reported_Date as "Reported date" ) filters ( Module Priority Status ) }

• zoho.loginuserid is the login email id of the user who is currently logged in to zoho creator. So the filter lists only those issues assigned to the currently logged in user.

• Lists all the issues assigned to you that are have already been closed.

list "Closed issues" { show all rows from Issue [(Status == "Closed" && Assigned_to.email == zoho.loginuserid)] ( Title Description Module Priority Reported_Date as "Reported date" ) filters ( Module Priority ) }

Page 169: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 168

View all Issues - Pending

• Lists all the issues that are still in open state

table "Open Issues" { show all rows from Issue [Status == "Open"] ( Title Module Priority Assigned_to as "Assigned to" ) filters ( Module Priority ) }

• Lists all the issues that are in the status "InProgress"

table "Issues in progress" { show all rows from Issue [Status == "InProgress"] ( Title Module Priority Assigned_to as "Assigned to" ) filters ( Module Priority ) }

Page 170: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 169

View all Issues Lists all the issues that have been filed.

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 ) }

Page 171: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 170

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.

Running the Application Steps to run the application:

• Go to http://www.zohocreator.com and login

• Click on Create Application and select the tab Import script

• Just copy and paste the code in the textarea available and click on Create button.

A Bug Tracker application will get created and you will be directed to the application automatically. View the complete script here - recruitment.ds

Page 172: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 171

Sample Application - Recruitment - Post Application

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 (

Page 173: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 172

displayname = "Contact Number" type = number ) Address ( type = textarea ) on success { opening = New_Opening [Position_Name == this.Applied_For]; if (opening.Status == "Closed") { sendmail [ To : this.Email_ID 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 : "[email protected]" Subject : "Applicants resume matches job profile" Message : this.Applicant_Name + " matches the job profile<br> Contach Info: " + this.Email_ID ] } else { sendmail [ To : this.Email_ID 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" ] } } }

Page 174: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 173

View Openings

• View all the available openings

list "Available Openings" { show all rows from New_Opening ( Position_Name as "Position Name" Status Position_Type as "Position Type" Experience ) filters ( ""Openings"" : Status == "Open" ) }

• View all the job profiles

list "All Job Profiles" { show all rows from New_Opening ( Position_Name as "Position Name" Status Position_Type as "Position Type" Experience ) }

Page 175: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 174

Admin - Add new opening

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} ) }

Page 176: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 175

Admin - View Applications

list "View All Applications" { show all rows from New_Applicant ( Applicant_Name as "Your Name" Email_ID as "Email ID" Date_of_Birth as "Date of Birth" Education Experience Applied_For as "Applied For" Contact_Number as "Contact Number" Address ) }

Page 177: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 176

Admin - Shortlist Candidates

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 [

Page 178: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 177

Subject : "Reg application for job posted at recruitment.zohocreator.com" Message : "Hello " + this.Candidate_Name + ", <br> Congratulations. You have cleared the written test. Please appear for an interview to be held on " + this.Date_Field + "<br> <br> Best Regards,<br> Recruitment Manager" ] } } ) Date_Field ( type = date ) Comments ( type = textarea ) }

Page 179: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 178

Students Marks Database

• 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 Running the Application Steps to run the application:

• Go to http://www.zohocreator.com and login.

• Click on Create Application and select the tab Import script.

• Just copy and paste the code in the textarea available and click on Create button.

A Student marks database will get created and you will be directed to the application automatically. View the complete script here - student_marks_database.ds

Page 180: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 179

Add student info • This form has the general information about all the students

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 ) }

Page 181: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 180

• View all the student information as a table.

table "Student Info" { show all rows from Student_Info_Form ( Student_ID as "Student ID" Student_Name as "Student Name" Date_of_Birth as "Date of Birth" Guardian_name as "Guardian name" Guardian_Mailid as "Guardian Mail ID" Nationality Date_of_Joining_the_course as "Date of Joining the course" ) }

Page 182: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 181

Enter student marks

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

Page 183: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 182

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" ] } } }

Page 184: Zoho Creator Deluge Script Help Document

Help Document Deluge Script

AdventNet, Inc. 183

View Student marksheet

This is the consolidated view of marks obtained by all the students.

list "View Mark List" { show all rows from Students_Mark_Sheet ( Student_Name as "Student Name" Maths Physics Chemistry English History Arts TotalMarks AverageMarks ) }

Page 185: Zoho Creator Deluge Script Help Document