Creator Help

For Each Value In List

Iterate Multiple Picklist Values (for each list value)

The for each list value Deluge statement enables you 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.

Syntax

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 - multiselectin 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.

Example

Visualize a simple application that calculates the total price of the selected products. The application has the following forms:

  • Products form to enter the product name and its rate.
  • Order form to order one or more products. Here, the Select Product field is a lookup field from the Products form. When a customer submits his order, the total price for the selected product is calculated and displayed in the order view. This is achieved by writing Add Record -> Record Add script in the order form, as given below:

on add
{
on success
{
val = 0.0;
for each Select_Product r in Order_form [ID == input.ID]
{
val = (val + r.Rate);
}
input.Total_Price = val;
}
}

Code Explanation:

  1. The on add -> on success script is executed when a customer submits his order in the Order form.
  2. The following code declares a variable named val to store the total price. The Set variableDeluge syntax is used to create this code.

    val = 0.0;

  3. Iterates through multiple products in Select_Product lookup field in Order form, with the currently submitted ID as criteria. The for each list value deluge syntax is used to create this code.

    - The criteria will fetch the records whose ID is same as the input ID.
    - r is the name of the collection variable that will hold the data corresponding to each iteration of the product.

    for each Select_Product r in Order_form [ID == input.ID]

  4. Append the val variable with the rate of each product. Again, the Set variable Deluge syntax is used to create this code. r.Rate will fetch this rate from the related Productsform.

    val = (val + r.Rate);

  5. When the total value is calculated, the Total_Price field is updated with the value. The Set variableDeluge syntax is used to create this code.

    input.Total_Price = val;

    To view the script,

    • Select on add -> on success script from the Workflow tab.

Top