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.

 

for each x in emprecords
  {
  sendmail
  (
  To : x.EmailID
  From : "yourmail@yourdomain.com"
  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 : "xxx@adventnet.com"
  From : "support@zohocreator.com"
  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
  ) 


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

 

Top

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)