I’ve had a request to expand on my post about generating automatic numbers for InfoPath forms. I was asked to go into more detail about how to set up a SharePoint list to act as a counter.
Go to the SharePoint site where you have your document library and create a custom list by the standard process. There are a couple of different ways to do this. You can click Site Actions, then create. Or you can click on lists to get a list of all the lists on the site, and then click create. Or you can click on view all site content, then create. Either way, you will be taken to a menu screen offering a selection of things that could be created. The top link in the fourth column is custom list. Click this.
Now you have a new list with only one column showing, title, and no elements.
Click on settings and then create column. Add a column that contains a number with no decimal places. I’ve called this count. It doesn’t really matter what you call this column, so long as you remember the name.
Once you’ve got the column, add an element to the list. It doesn’t matter what you put in the title field but you need to put 0 in the count column (assuming there are currently 0 forms in your library).
That’s your counter made.
Now, open up SharePoint Designer. You’ll want to create a new workflow. Select the options to attach this workflow to the form library you want to set the auto-numbering in. Disable the options to allow users to manually start the workflow or to start the workflow when items change. Either of these would mess up your numbering.
Click next to get to the next screen in the wizard. This is an extremely simple workflow that only requires two actions. Click on the action button and add the inbuilt actions do calculation and update list item. Click on the first blue “value” links in the do calculation action, then click the function button that appears. This gives you the opportunity to choose an existing value. For source, choose your counter list with the count field as the field. Now SharePoint needs to know which item to bring back from this list, so set the field to be the ID field and the value to be 1 (since there’s only one item in this list). For the second value, just enter 1.
In the update list item action, click the blue this list. From the drop-down menu, choose the counter list. Add a field to be updated and choose the count field, selecting as the new value the calculated value (from the workflow data). Again, you need to specify the exact list item. Select the field ID and the value 1.
Then click finish. Now your counter will increment every time a form is added to your library. You can now reference this list from your InfoPath forms to create the form ID number.