The deluge language now supports a second level of iteration to iterate through multiple list values in a row. For example, if there are n rows in a form and for each row there are m values in a multiple list field, you can iterate through the m values in the list within each row.
for each <fieldname> <variable> in <formname/rowvariable> [criteria]
where,
formname\rowvariable - name of the form whose data has to be iterated one by one or the name of the row variable that contains the data for a single record corresponding to each iteration.
criteria - in most of the cases, you would like to conditionaly fetch the data. You can specify your criteria for fetching the form data here. It is an optional parameter.
fieldname - name of the form field of type Import data from form - multiselect in the above form/row, whose values has to be iterated one by one.
variable - name of the variable that will hold the data corresponding to each iteration of the above fieldname.
Visualize a simple Sports Registration application. It has two forms.
1. The form Sport_Coaching_Details has the following fields.
Sport_Name - Name of the sport for which coaching is offered.
Minimum_Age - Minimum age required for the sport.
Maximum_Age - Maximum age limit for each sport.
Fees - The fees collected for coaching.
2. The form Sports_Registration has the following fields.
Name - Name of the person who would like to register himself for coaching for one or more sport.
Emailid - Valid email id of the person.
Age - The age of the person registering.
Sports - This field is a lookup field imported from Sport_Name field in Sport_Coaching_Details form and is of type multiselect. (i.e) a person can register for one or more number of sport, from this list.
Both the forms are related since there is a import data field between them. So it is possible to get the Sports details from the Sport_Coaching_Details form for any given sport in Sports_Registration form.
For each Sport registered, we have to check if the age specified is within the agelimit prescribed for that sport as specified in form Sport_Coaching_Details. If so, an email is sent with the message that the registration for that sport is accepted. The following code in the on success event block does this.
Deluge code snippet
on success { if (count(Sports_Registration) >= 15) { // iterates through each row in the Sports_Regitration form for each r in Sports_Registration { //iterates through multiple values specified for the Sports field in the row r for each Sports x in r { if ((r.Age > x.Minimum_Age) && (r.Age < x.Maximum_Age)) { sendmail ( To : r.Emailid Subject : "Registration for Sports coaching from " + r.Name Message : "Your registration for" + x.Sport_Name + "is accepted" ) } } } } }where,
Sports - fieldname in the Sports_Registration form whose values has to be iterated one by one.
x - variable that will hold the data corresponding to each iteration of the above fieldname
r - row variable that contains the data for a single record for each iteration in Sport_Registration.
Deluge code explanation
1. Checks whether the total registration is greater than or equal to 15. Here, Sports_Registration is the name of the form.
if (count(Sports_Registration) >= 15)
2. Iterates through each row in the Sports_Registration form. Here, r is the name of the row variable that contains the data for a single record corresponding to each iteration.
for each r in Sports_Registration
3. Iterates through multiple values specified for the Sports field in the row r. Here, Sports is the name of the field in the Sports_Registration form whose values has to be iterated one by one and x is the name of the variable that will hold the data corresponding to each iteration of the Sports field.
for each Sports x in r
4. Checks whether the Age specified in the Sports_Registration form, is within the Minimum_Age and Maximum_Age limit specified for this sport in the Sports_Coaching_Details form.
- r.Age fetches the Age value from the row variable r in Sports_Registration form.
- x.Minimum_age will fetch the Minimum_age for this Sport from the Sports_Coaching_Details form.
if ((r.Age > x.Minimum_Age) && (r.Age < x.Maximum_Age))
5. The sendmail function is called to send an email to the Emailid specifed in row r.
sendmail ( To : r.Emailid Subject : "Registration for Sports coaching from " + r.Name Message : "Your registration for" + x.Sport_Name + "is accepted" )
Example : Using Script Builder
Let us add the on success action script for the Sports Registration Example using Script Builder. The following deluge features are used in this example:
1. Select On Success Form Action
a. Select the form Sports_Registration from the list of forms displayed in the top left corner of the script editor.
b. Select Form Actions -> On Success. Sample form actions will be displayed in the editor area. Delete the sample statements.
a. Select Control Flow -> For each record from the left-side tree and drag and drop it in the editor area. The syntax to iterate each row in a form will be displayed as shown in the screen-shot below.
b. Select Edit option to specify the row variable and criteria, if any.
f. The 'for each record' Edit dialog will be displayed as shown in the screen-shot given below:
Select the form name whose data has to be fetched. In this example, the form name is Sports_Registration.
Declare the rowvariable name as any user defined name. Here we specify the name as r.
Since we want to iterate through all the records, we do not specify any criteria.
Click Done to add the script in script editor.
The deluge statement to iterate each row r in the form "Sports_Registration" is added to the script editor, as shown below:
2. for each list value: Now we have to iterate through multiple values specified for the Sports field within each row r. To do this,
a. Drag and drop Control flow -> for each list value to the text editor area. The syntax is displayed as shown in the screen-shot given below. Click on Edit to specify the required details.
b. Select the row variable r that contains the data for a single record for each iteration in Sport_Registration.
c. Select the form field Sports in the above row variable r, whose values has to be iterated one by one.
d. Declare a user-defined variable name x, that will hold the data corresponding to each iteration of the Sports field in r.
e. Click on Done to add the for each syntax to the script editor.
![]()
Note: When a formvariable/collectionvariable is selected instead of formname, the dialog does not display the criteria text box.
The deluge for each list value is added to the script editor, as shown below:
a. Drag and drop the If control flow statement, as highlighted in the screen-shot below. Click on Edit to specify the If condition.
b. The Edit dialog for If is displayed as shown below, wherein you have to create the If condition. In our example, we have to check if the Age specified in Sports_Registration is within the maximum and minimum age limit specified in the Sports_Coaching form.
Select the Collections Tab to display the collecton variables. Select the variable r from the Variables list . Here, r contains the data for a single record corresponding to each iteration in Sports_Registration.
Click on the Age field from the list of fields in the variable r. The condition r.Age will be added to the text area below.
Add the > operator from the list of operators.
Select the Collections Tab and select the collection variable x from the Variables list . Here, x is the name of the variable that will hold the data corresponding to each iteration of the Sports field.
Click on the Minimum Age field from the list of fields in the variable x.
Select the && operator from the list of operators and add the second condition to check if the Age specified is less than the Maximum_Age.
Click Done to add the If condition to the script editor.
4. Send mail : Now, we have to add the If statements to be executed, when the If condition is satisfied. In our example, we have to send a mail to the email id specified in the Sports_Registration form if the condition is satisfied.
a. Drag and drop the Send mail function to the editor area, as highlighted in the screen-shot below. Refer the Send mail topic, for more information on the syntax and usage.
b. Click on Edit to specify the To address, Subject and Message for Send mail. The Edit dialog displays the default values. To modify the default values, click on the icon on the right-side of each field. For example, to send an email to the Emailid specifed in row r, select the Emailid field from the collection variable r.
Note: The email id of the application owner will be taken as the From Address.
c. The send mail script is added to the script editor as shown below. Click Save Script to add the action script to the script definition.
The above action script will send an acceptence email to the registered persons if the age specified in "Sports_Registration" is within the age limit prescribed for that sport as specified in form Sport_Coaching_Details.