For each element
Table of Contents
Overview
The for each element deluge task iterates through all the elements present in a list, comma-separated text, or a CSV file.
Syntax
for each <elementVariable> in <variable>
{
}
{
}
Parameter | Description |
---|---|
<elementVariable> | Variable to hold an element for each iteration. You can specify any variable name here, without having to declare it initially. After the iteration, this variable will hold the last element in the list. |
<variable> | The variable containing the elements which will be iterated. Supported data types:
Note: The size of the input CSV file cannot be more than 2MB. |
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 |
Example 1: Iterate through a list
The following example displays all the element present in the list - numbers
//Create a list
numbers = {"One", "Two", "Three"};
//Iterate through each element of the list using for each
for each item in numbers
{
info item;
}
numbers = {"One", "Two", "Three"};
//Iterate through each element of the list using for each
for each item in numbers
{
info item;
}
Example 2: Send mail for every iteration
In the following example, the code snippet iterates through each team in the list and executes the send mail task for each iteration. "Employees" is a form with "Team" and "EmailID" fields.
//Create list to hold teams
teamList = {"Zoho Creator", "Zoho CRM"};
//Iterate through the list using for each task
for each temp in teamList
{
//Send mails to every team from the list using the sendMail task
sendMail
[
from: zoho.adminuserid
to: Employees[Team = temp].EmailID.getall();
Subject: "Working day for "+temp
Message: "Coming Saturday will be a working day"
];
}
teamList = {"Zoho Creator", "Zoho CRM"};
//Iterate through the list using for each task
for each temp in teamList
{
//Send mails to every team from the list using the sendMail task
sendMail
[
from: zoho.adminuserid
to: Employees[Team = temp].EmailID.getall();
Subject: "Working day for "+temp
Message: "Coming Saturday will be a working day"
];
}
Example 3: Iterate values of a CSV file
//Download a Zip file using invokeUrl task
csv_file_zip = invokeurl
[
url: "https://www.stats.govt.nz/assets/Uploads/Business-financial-data/Business-financial-data-June-2021-quarter/Download-data/wholesale-trade-survey-june-2021-quarter-csv.zip"
type: GET
];
csv_file_zip = invokeurl
[
url: "https://www.stats.govt.nz/assets/Uploads/Business-financial-data/Business-financial-data-June-2021-quarter/Download-data/wholesale-trade-survey-june-2021-quarter-csv.zip"
type: GET
];
//Extract the csv file from the downloaded zip file
csv_file = csv_file_zip.extract().get("wholesale-trade-survey-jun-2021-quarter-csv.csv");
//Iterate values of the extracted CSV file
for each val in csv_file
{
info val;
}