Count Function

 Count function

The count function returns the number of rows in a Form / Form variable.

 Syntax

count(formname[<expression>])

 Example

  1. The following sample code, added to the on submit block, checks for uniqueness of a record. If the name specified in the form data already exists in the team_member form, the data is not submitted.

    on success
    {
    if (count(team_member[name == input.name]) > 0)
    {
    cancel submit;
    }
    }

    where,

    team_member - is the name of the form.
    team_member [name == input.name] - selects all the team_members whose name is equal to the name currently entered in the name field.
    input.name - it is the value for the field "name" given by the user while submitting the form
    count - count operator returns the number of team members whose name is equal to input.name

  2. The following sample code, added to the on success block, limits the number of records in a form.

    on success
    {
    if(count(Employee)>= 20)
    {
    alert("No more registrations allowed");
    cancel submit;
    }
    }

    where,

    Employee - is the name of the form
    count - count function returns the number of records in the Employee form.

  3. The following sample code added to the on success block, will pass the count value to a variable and display the result. Here, var1 is the user-defined variable which holds the total number of records in FormA, with the given criteria. The criteria [ID!=0], returns all the records in FormA.

    on success
    {
              var1 = count(FormA[ID!=0 ]);
              info var1;
    }