For each record
Table of Contents
Note:
- This task is applicable only to Zoho Creator.
Overview
The for each record deluge task iterates through a form's records, which are retrieved based on a given criteria.
The criteria is optional.
Note:
- The fetched records may appear to be sorted based on "added time" (oldest first) system field. However, there is no guarantee to this order and there is no guarantee that the order will remain constant over time. If you are particular about the sequence of the records, it is advisable to use the sort param.
Syntax
To iterate through records which meet a criteria
for each <loop_variable> in <form_link_name> [<criteria>];
To iterate through records sorted in ascending order based on specified field, which meet a criteria
for each <loop_variable> in <form_link_name> [<criteria>] sort by <field_link_name>;
To iterate through records sorted in descending order based on specified field, which meet a criteria
for each <loop_variable> in <form_link_name> [<criteria>] sort by <field_link_name> desc;
To iterate through records within a specified range, which meet a criteria
for each <loop_variable> in <form_link_name> [<criteria>] range from <start_index> to <end_index>;
To iterate through records sorted in ascending order based on a field within a specified range, which meet a criteria
for each <loop_variable> in <form_link_name> [<criteria>] sort by <field_link_name> range from <start_index> to <end_index>;
To iterate through records sorted in descending order based on a field within a specified range, which meet a criteria
for each <loop_variable> in <form_link_name> [<criteria>] sort by <field_link_name> desc range from <start_index> to <end_index>;
Parameter | Description | |||||
---|---|---|---|---|---|---|
<loop_variable> | Variable to hold an individual record for each iteration. You can specify any variable name here, without having to declare it initially. It is advisable to not use the same loop variable used earlier. | |||||
<form_link_name> | Link name of the form from which the records will be fetched. | |||||
<criteria> | Criteria based on which the records will be fetched. | |||||
sort by <field_link_name> | Link name of the field based on which records will be sorted. If you do not specify asc or desc, the records will be sorted in ascending order. | |||||
range from <start_index> to <end_index> | Records falling in the specified index range will be fetched.
Negative index values will return an error during runtime. |
Things to keep in mind
- If you wish to fetch all records of the specified form, use the following script as criteria:[ID != 0]
It is advisable to fetch all records only when absolutely needed. Fetching all records generates a load resulting in performance issues. - If you wish to use the "sort" and "range" parameters together, the "sort" parameter should be followed by the "range" parameter.
This task can be used in the following events
When a record is Created | ||
On Load | Yes | |
On Validate | Yes | |
On Success | Yes | |
On User input | Yes | |
Subform on add row | Yes | |
Subform on delete row | Yes | |
When a record is Created or Edited | ||
On Load | Yes | |
On Validate | Yes | |
On Success | Yes | |
On User input | Yes | |
Subform on add row | Yes | |
Subform on delete row | Yes | |
When a record is Edited | ||
On Load | Yes | |
On Validate | Yes | |
On Success | Yes | |
On User input | Yes | |
Subform on add row | Yes | |
Subform on delete row | Yes | |
When a record is Deleted | ||
On Validate | Yes | |
On Success | Yes | |
Other workflow events | ||
On a scheduled date | Yes | |
During approval process | Yes | |
During payment process | Yes | |
In a Custom Function | Yes | |
In an Action item in report | Yes |
Examples
1) The following script fetches all records from the Employees form and stores them in "EmployeeDetails" collection variable. The "Name" field value is extracted from all the records and displayed to the user.
{
info EmployeeDetails.Name;
}
2) The following script iterates through all records in the "Employees" form which meet the criteria, and a mail is sent to those employees.
//subYear is a <built-in function>
//zoho.currentDate is a which holds current(today) date value.
{
sendmail[
form:zoho.adminuser
to:employee.emailID
subject:"Work Anniversary"
message: "Here's wishing you a very happy work anniversary."
]
}
3) The following script iterates through all records in the "Employees" form which are sorted based on the "name" field, and displays the field value in the first 3 records.
{
info employeeDetails.name;
}