A clear <picklist> function clears all the values in a picklist and displays an empty picklist. It can be is used in On Load form action to display an empty picklist when the form is loaded and in On User Input field actions to display an empty picklist dynamically, based on a specified criteria.
clear <single select list fieldname> |
Let us take a Bug Tracker application as an example. It has three forms.
- Form to fill in the module names. e.g. In the case of Zoho Creator, it could be user interface design, deluge script etc. See a list view of all the modules added.
- Form to fill in the team member details. It has the name of the team member and the module he works for. See a list view of all the team members (and the respective modules).
- Form for filing issues. Each of the issues filed has to be assigned to the appropriate team member. Since we have already defined the person in charge for each of the modules, it will make more sense if the items in the Assigned to picklist gets updated every time the module is changed, listing only the relevant entries.
If Persistence is selected in the Module picklist, only those members of the team, in charge of the Persistence module should get listed in the Assigned to picklist. In this example, Edward and John should get listed. In the following script, we have added an if condition to the same example to check if the module selected has one or more team members. If the module does not have any team members, the Assigned_to picklist field will be cleared.
The following deluge code does this.
form FileIssue { Title ( type = text ) Description ( type = textarea ) Module ( type = picklist values = Module.Module_Name on user input { if (count(TeamMember[Module == input.Module]) == 0) { clear AssignedTo; } else { team = TeamMember [Module == input.Module]; for each t in team { AssignedTo.add(t.Name); } } ) Priority ( type = radiobuttons values = {"Very High", "High", "Medium", "Low"} ) Status ( type = checkboxes values = {"Open", "Close", "In-Progress"} ) ReportedDate ( displayname = "Rep.Date" type = date ) AssignedTo ( type = picklist values = TeamMember.Name ) }
Explanation:
The code snippet given below uses the count deluge function to count the number of records in the TeamMember form, whose Module name is equal to the Module selected in the FileIssue form. fetches all the members of the team, in charge of the selected module.
if (count(TeamMember[Module == input.Module]) == 0)
{
clear AssignedTo;
}
If the count is 0, (i.e) no records in TeamMember form with the selected Module name, the AssignedTo picklist field will be cleared. If the count is more than 0, the else statements will be executed.
if (count(TeamMember[Module == input.Module]) == 0)
{
clear AssignedTo;
}
2. else statements
The code snippet given below fetches all the members of the team, in charge of the selected module.
else { team = TeamMember [Module == input.Module]; for each t in team { AssignedTo.add(t.Name); } }
Since the variable team is an array, it has to be iterated to get the properties of each team member.
for each t in team { Assigned_to.add(t.name); }
The names of those team members in charge of the Persistence module are added to the Assigned to picklist.
for each t in team { Assigned_to.add(t.name); }
Let us add the deluge code for the above example, using script builder. Click here, to view the form.
1. Add On User Input field action: To add an action when the Module field in FileIssue form is changed,
a. Select the form FileIssue from the list of forms displayed in the top left corner of the script editor.
b. Select Field Actions -> Module -> On User Input, as shown in the screen-shot below.
a. Drag and drop the If control flow statement, as highlighted in the screen-shot below. Refer the If, else if, else topic, for more information on the syntax and usage.
b. Click on Edit to specify the If condition.
c. The Edit dialog for If is displayed as shown below, wherein you have to create the If condition.
![]()
Note: Count function is currently not supported in script editor. Hence, you have to manually specify the condition with the count function as shown below. Refer the topic, Count function for more information.
d. Click Done to add the If condition to the script editor.
The if condition will count the number or records in the TeamMember form with module name same as the module name entered by the user in the current form. The if statements will be executed, if the count is 0. (i.e) if no such records exists.
Clear Picklist: In our example, the AssignedTo picklist must not display any value if no records exists in the TeamMember form with the input module name.
a. To clear a picklist field, drag and drop Client Functions -> Clear Picklist.
b. Click on Edit to specify the picklist fieldname.
c. Click Done to add the field name to the script editor.
d. Add the else syntax to the script editor, to execute statements if the if condition is satisfied.
3. Fetch Records - To fetch records from the form TeamMember whose module name is equal to the module name input, and store it in a collection variable,
a. Select Data Access -> Fetch Records from the left-side tree and drag and drop it in the editor area. The syntax to fetch records from a form, will be displayed as shown in the screen-shot below:
b. Select Edit option to specify the variable name, formname and criteria to fetch the records. The Fetch records 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 TeamMember.
Specify the collection variable to store the fetched records, as any user defined name. Here we specify the name as team.
Now you have to specify the criteria based on which the data is to be fetched from the TeamMember form. In our example, we have to fetch the records from TeamMember whose Module name is same as the Module currently chosen(input) in the FileIssue form. To do this, select the tab Criteria fields. This will display all the fields in the TeamMember form.
Select Module to add it to the value textbox.
Select the == symbol to add it to the value textbox.
Select the tab Input fields to display fields available in the input form. In our example, the FileIssue is the form whose values are currently input by the user.
Click on Module from the list. You will now find the syntax input.Module added in the text area.
Click Done to add the syntax to the text editor.
The deluge syntax to fetch the records is added to the script editor, as shown below:
4. for each statement: Now, we need to iterate through each row in the formvariable team and add the name of the team member to the AssignedTo picklist field. To do this,
a. Drag and drop Control flow -> for each record to the text editor area. The syntax for the for each statement is displayed as shown in the screen-shot given below. Click on Edit to specify the required details.
b. The for each record dialog is displayed as shown below:
Select the collection variable team from the list. This variable stores the records fetched from the TeamMember form.
Specify the rowvariable as any userdefined name. Here, we will specify the rowvariable as t.
![]()
Note: In our example, we have already fetched the records from teammember form and stored in a variable named team. So we will specify this collection variable team, instead of formname[criteria]. When a collection variable is selected instead of formname, the dialog does not display the criteria text box.
c. Click Done to add the for each syntax to the script editor.
The deluge for statement to iterate each row t in the formvariable team is added to the script editor, as shown below:
5. Add to Picklist: For each row t in the formvariable team, we have to add the Name to the Assignedto picklist field.
a. Drag and drop Client functions -> Add to picklist to the text editor area. The syntax for the add statement is displayed as shown in the screen-shot given below. Click on Edit to specify the picklist name and value.
b. The Add to Picklist dialog is displayed as shown below.
The Select picklist name listbox will display all the picklist fields in the current FileIssue form. Select AssignedTo picklist from the list of picklists displayed.
Select the collection variable t from the variables list and click on the Name field.
You will now find the syntax t.Name added in the text area.
Click Done to add the syntax to the text editor.
c. The deluge statements to fetch records, iterate each row and add to picklist dynamically, is added to the script editor as highlighted below. Click Save Script to add the On User Input action to the script.
e. To view the complete script with the onload action, select Form Definition -> With Action or select Free-flow Scripting. The on load action script is successfully added to the form definition, as shown below.
6. When a Module is selected in the fileIssue form, only those members of the team, in charge of the that module will get listed in the Assigned to picklist.