How To: Use the Count Function

This topic shows you how to use the List > Count function to count the number of items in a SharePoint list.

The Count function works with SmartObject list methods configured to return all items as a collection.

The solution used in this example shows you how to configure the Count function with a Get List Items method using All items as a collection.

Scenario

As part of an office meals club, your company uses a SharePoint list to add employees to the club. A simple list of Title, Name, and Telephone number is kept to track who is in the club. The SharePoint list is made into a K2 Application with a SmartObject, SmartForm, and a workflow. When a new person is added to the club, a workflow starts, sending an email to the list owners with the title, name, and phone number of the new member. A total (using the Count function) of how many people are part of the meal list is included at the end of the email.

Steps

  1. Create a Meal Club list in SharePoint with Title, Name, and Telephone number columns
  2. Integrate your list with K2, selecting SmartObject, SmartForm, and Workflow
  3. In the workflow, add a Send Email step
  4. Specify Meal Club: New Person Added as the Subject
  5. Drag and drop the Title, Name, and Telephone number fields from the References tab. Insert a space between the Title and Name fields and put the Telephone number on a new line.
  6. Type in Total number of Club Members: then open the Context Browser > Functions tab, locate the Lists > Count function and drag it into the email as shown below:
  7. Locate your Meal Club list in the Context Browser > SmartObjects tab (in this environment it is in the SharePoint 2013 category), expand the Get List Items method, and drag the ID field into the Count function
  8. Configure the Get List Items Method as All items as a collection
  9. Deploy your workflow
  10. Add a new member to the SharePoint list. The email is sent to you giving the details of the new member with the running total number of members.