The count function in Deluge Scripting enables you to count the number of records in a Form (table) that satisfies the given criteria. Using the count function, you can check if an entry already exists in a database. Let us illustrate this with the help of an example:
Assume, you have two forms: Members and Orders.
- Members form contains the list of registered members with a valid MemberID, who are eligible to subscribe through Orders form .
- Orders form is used by registered members to submit their order. Hence, when a user submits data through Orders form, we need to validate to check if the user is already a registered member. This is achieved by writing Form Actions -> On Add -> On Validate script in Orders form , as given below:
if (count(Members[MemberID == input.MemberID])== 0)
{
alert " Specified MemberID is not Found in Members list";
cancel submit;
}
Code Explanation
1. The count built-in function will return the number of rows fetched from Form A, with the given criteria:
if (count(Members[MemberID == input.MemberID]) == 0)
2. The alert statement is executed if the count function returns 0
alert "
Specified MemberID is not Found in Members list";
3. cancel submit statement will cancel the record update operation
cancel submit;