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 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
- Create a Meal Club list in SharePoint with Title, Name, and Telephone number columns
- Integrate your list with K2, selecting SmartObject, SmartForm, and Workflow
- In the workflow, add a Send Email step
- Specify Meal Club: New Person Added as the Subject
- 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.
- 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:
- 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
- Configure the Get List Items Method as All items as a collection
- Deploy your workflow
- 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.