Iterating Data in Radio buttons/Check boxes
This topic illustrates the usage of the for each list value statement
supported by Deluge, to iterate multiple list values, within each record.
The for each list value deluge statement can be used to
iterate multiple list values within each record. For example, assume you
are creating an application with a form to assign tasks to staff members.
Multiple tasks can be assigned to each staff. Once the tasks are assigned,
an email is sent to the respective staff informing him about the list
of tasks assigned. So, the data held by the multi-select Tasks
field needs to be iterated, to fetch all the tasks assigned to a staff.
Let us illustrate this with the help of a sample application, "Task
Management".
About the application
The Task management application comprises of three forms;
- Staff Details: To enter the staff details with fields name
and E-mail id.
- Tasks: To enter the list of tasks and its description
- Assign Task: To assign one or more tasks to a staff on any
specific date, where tasks and staff are lookup fields imported from
the respective forms. When a task is assigned, an email is sent to
the staff informing him about the list of tasks assigned. This is
achieved by adding On add -> on success script, to this
form, as shown below. The script uses the for each list value
deluge statement to iterate multiple list values within a record.
Code Explanation:
1. The on add -> on success script is executed whenever a
record is submitted using the Assign Task form.
2. The following code declares a variable named
temp to store the values of tasks assigned and set with null
value. The Set variable Deluge syntax is used to create
this code.
3. Iterates through multiple values in Tasks_Assigned lookup
field in the Assign Task form, with the specified criteria.
The for each list value deluge syntax is used to create
this code.
- The criteria will fetch the records whose staff name and Assigned
Date is same as the input staff name and date.
- r is the name of the collection variable that will hold
the data corresponding to each iteration of the above file name.
| for each Tasks_Assigned r in Assign_Task
[(Staff == input.Staff && Assigned_Date == input.Assigned_Date)] |
4. Append the temp
variable with each task value. Again, the Set variable
Deluge syntax is used to create this code. r.Task will
fetch this task name from the related Tasks form.
| temp = temp + r.Task + "<br>"; |
5. Fetch the record from Staff Details
form with the specified criteria and store it in variable named rec.
The Fetch records deluge syntax is used to create this
code.
| rec= Staff_Details [Staff_Name ==
input.Staff]; |
6. The sendmail function is called to send an
email to the Emailid of the staff. Here, rec.Email_Id,
will fetch the email id from the rec variable and temp will
contain the list of tasks assigned to this staff.
sendmail
(
To : rec.Email_Id
From : zoho.adminuserid
Subject : "Subject of the email"
Message : "The following tasks are assigned to you: <br>"
+ temp
) |
|