The for each syntax in Deluge scripting, enables you to conditionally fetch a collection of records and iterate over them. Let us illustrate this with the help of a simple example. The CEO of a company wants to address all the new employees who have joined after certain date say, '10-jun-2007' . We have to mail all these new employees. Lets see how we can achieve this.
1. Form 'Employee' has the following fields: Name, Qualification, EmailID, TeamName, JoinDate
2. Write Form Actions -> on add -> On success script, as given below:
for each x in Employee [JoinDate > '10-Jul-2007']
{
sendmail
(
To : x.EmailID
From : "yourmail@yourdomain.com"
Subject : "Meeting at 6:pm tomorrow"
Message : "As our CEO wants to address the new employees, you are requested to attend the meeting.<br>Thanks"
)
}
Code Explanation
for each x in Employee [JoinDate > '10-Jul-2007'] -
Fetch the records from the Employee form with the given criteria and iterate over each record, to send mail to the EmailID of each record. Here 'x' is the instance variable that will represent a single record in each iteration.
sendmail
- The deluge function to send mail
x.EmailID
- Refers to the emailid of each record