Count listitems in InfoPath

In some cases you want to count the number of items in a SharePoint list and do something with that value. Let say show or hiding a control in InfoPath. This is how you can do this:

Add a new datasource to you InfoPath form that points to your list that you want to count:

image

image

image

image

Select the ID column. It really doesn’t matter what columns you select.

After you created the datasource we add a textbox to the form to display the number of items in the form:

image

Now modify the properties of the textbox by right clicking on it and select Text Box Properties:

image

We will set the default value of the textbox, so click on the formula button: image. We use a function to count the items. The function is called: Count(), what a coincidence Glimlach

image

We will count the number of items in the datasource we just created:

image

Make sure you select the “dataFields” SharePointListItem folder and not the queryFields one.

You can use the “filter data” button to filter the items before counting.

image

That’s all you have to do, besides clicking “OK” a few more times. Now you can preview your form and you can see the number of items in the list.