Counting the amount of documents submitted today to a SharePoint library
Use an XPath expression to count the amount of documents that were submitted today to a SharePoint library.
Problem
You want to count the amount of documents that were submitted to a SharePoint library on the current day.
Solution
Use an XPath expression to count the amount of documents that were submitted today to a SharePoint library.
Discussion
Each SharePoint library has a field called Created in which the current date and time is stored when a document is created. So the first step is to create a Data Connection to the SharePoint library that stores the documents that you want to count. When you create this Data Connection, make sure to select the Created field from the list of available fields in the Data Connection Wizard. Now the secondary data source that is bound to the library will contain this field too.
The next step is to create a Rule that for example sets the value of a field on the InfoPath form to the amount of documents in the library that were created today. The formula for the amount would look something like the following (with the Edit XPath (advanced) checkbox selected) where MySharePointLib is a secondary data source:
count(xdDocument:GetDOM("MySharePointLib")/dfs:myFields/dfs:dataFields/dfs:MySharePointLib[substring-before(@Created, " ") = xdDate:Today()])
Since the date in the Created field of the SharePoint library has the format yyyy-MM-dd hh:mm:ss and you only need the first part before the space, which is yyyy-MM-dd, to perform the calculation, you can use the substring-before() function to look for the space and return only the first part of the date. Then you can compare this with the date of today (xdDate:Today()) to filter the items in the secondary data source that is bound to the SharePoint library on only those documents that were submitted today.
Tip:
To always have an up-to-date count, in the same Rule, before you run the Action to count,
you can create a Query using data connection Action on the secondary data source to refresh the
data just before you perform the calculation.
Note:
If the formula is returning an inaccurate count, you may be using the wrong view in SharePoint. When you create a Data Connection to
a SharePoint library, by default InfoPath uses the All Documents view defined on the SharePoint library.
If you want InfoPath to use a view other than the All Documents view as the Default view on the SharePoint library, you can
use the method described in Populating form data from SharePoint List Views
to be able to bind a Data Connection to a specific SharePoint view that InfoPath should use to retrieve the items from the SharePoint library instead of the standard
method described in this article.
Related InfoPath Articles:
- Count the total amount of sections in a Repeating Section in InfoPath on insert or delete
- How to add a data connection to a SharePoint list or library in InfoPath
- How to submit the rows of a repeating table in InfoPath to a SharePoint list
Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent of S.Y.M. Wong-A-Ton. Usage of techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author, S.Y.M. Wong-A-Ton.



