I want to create a Menu form with multi-select fields that list the menu items in each food category. Can you explain how I can use Deluge List task to manipulate the list values?

I want to create a Menu form with multi-select fields that list the menu items in each food category. Can you explain how I can use Deluge List task to manipulate the list values?

The Buffet Menu application illustrates the usage of the Deluge List function. The application comprises of a Menu form with multi-select fields that list the menu items in each food category. Selection of the food items for the buffet is subject to the following restrictions:

  • Only a total of ten items can be chosen from the different categories.
  • A minimum of one item must be selected from each category.
  • Only three premium items can be included.

When the Menu form is submitted, the validate script is executed to validate the form data for the above said conditions. The script uses the list functions to validate the data.


Adding Deluge Script

1. Validate script to validate form data

Menu form -> actions -> on add -> submit -> on validate

 actions
{
on add
{
submit
(
type = submit
displayname = "submit"
on validate
{
if ((input.Main_course.size() + input.Starters.size()+input.Desert.size()+input.Soups.size())> 10)
{
alert "Altogether only 10 items can be selected";
cancel submit;
}
if ((((input.Main_course.size()< 1) || (input.Starters.size()< 1)) || (input.Desert.size()< 1))
|| (input.Soups.size()< 1))
{
alert "Atleast one item must be selected from each category";
cancel submit;
}
totalList = List();
totalList.addall(input.Main_course);
totalList.addall(input.Starters);
totalList.addall(input.Desert);
totalList.addall(input.Soups);
noOfPremium = 0;
for each elem in totalList
{
if (elem.contains("-- Premium"))
{
noOfPremium = (noOfPremium + 1);
}
}
if (noOfPremium > 3)
{
alert "Only three premium items are allowed";
cancel submit;
}
}

)
}

Code Explanation

a. In the following code, the If condition sums up the number of items in each list using the <list>.size() funtion. If the total items selected exceeds 10, an alert message is displayed and the submission is canceled. 

if ((input.Main_course.size()  +  input.Starters.size()  +  input.Desert.size()  +  input.Soups.size())  >  10)
{
alert "Altogether only 10 items can be selected";
cancel submit;
}


b. In the following code, the If condition checks it at least one item is added in each category using the <list>.size() funtion. If not, an alert message is displayed and the submission is canceled.

if ((((input.Main_course.size()  <  1)  ||  (input.Starters.size()  <  1))  ||  (input.Desert.size()  <  1))  
|| (input.Soups.size() < 1))
{
alert "Atleast one item must be selected from each category";
cancel submit;
}

c. In the following code, 

  • A new list named totalList is created.
  • The <list>.addall deluge task adds the elements in the given list to the totallist.
  • Each element in totallist is iterated to check for the total number of premium items ordered. If the premium items exceed 3, the. is used to add the items in the list to a list If condition sums up the number of items in each list using the <list>.size() funtion. If the total items selected exceeds 10, an alert message is displayed and the submission is cancelled. 
totalList = List();
totalList.addall(input.Main_course);
totalList.addall(input.Starters);
totalList.addall(input.Desert);
totalList.addall(input.Soups);
noOfPremium = 0;
for each elem in totalList
{
if (elem.contains("-- Premium"))
{
noOfPremium = (noOfPremium + 1);
}
}
if (noOfPremium > 3)
{
alert "Only three premium items are allowed";
cancel submit;
}

2. On user input script

The on user input script is executed when you select/change the value of a field in your form. The script calculates the total number of items selected and displays it in a Note field. This script is added to all the multi-select list fields.

Desert
(
type = list
values = {"Italian delight (Cake)", "Chocolate Opera (Cake)", "Ambrosian delight (Ice Cream)",
"Jumbo delight (Ice Cream)", "Pista Pasta (Ice Cream) -- Premium"}
on user input
{
input.plain1 = ("<b><ul>No of items selected:" + ((input.Main_course.size()
+ input.Starters.size() + input.Desert.size() + input.Soups.size())))
+ "</ul></b>";
}

To install the application,

  1. Download the script file (.ds file)
  2. Install the application to your account. Click here to learn how to install using the script file (.ds file)
    • Related Articles

    • Attachment Category

      Attachments refer to any document, file or image that is related to a particular record. You have the option to add multiple categories of attachment to each module. For example, Candidate Resumes, Cover Letters, or even job descriptions for all your ...
    • Attachment Category

      Attachments refer to any document, file or image that is related to a particular record. You have the option to add multiple categories of attachment to each module. For example, Temp Resumes, Cover Letters, or even job descriptions for all your ...
    • Task layouts & fields

      Zoho Projects supports custom fields and layouts for tasks. Create your own fields and task layouts and use them for creating tasks as per your business requirements. Click here to learn more about access privileges for Custom Fields and Task ...
    • How can I get the values entered for certain fields via Deluge script?

      Many a times, when you are developing an application, you may need to get the value(s) entered for the fields in the form. To get the particular value, you can do so in Deluge Script, using the statement: input.<Field Name>For ex, if you would like ...
    • Create and manage fields

      Custom fields are the important aspect in shaping a layout. A layout is structured with a list of fields that are specific to your requirements. Once the user creates a layout they can start adding custom fields.    Default Fields: The default fields ...