Add an Auto-numbering field to an InfoPath Form


Thanks to some Twitter help from Clayton Cobb and Saed Shela and Clayton’s blog post on Auto-Numbering InfoPath Forms, I got a solution that works perfectly and requires nothing but the InfoPath form itself. I previously had a solution using the Do Calculation method of a SharePoint Designer workflow, but I would much rather do it all in InfoPath.
What I needed was to automatically number the InfoPath Form in a SharePoint 2010 Form Library. I could’ve just used the ID field, but my client is replacing a process that was previously manually numbered from 1 all the way up to the 4500+ range (and increasing daily). I’m preparing this process so that we can do a cutover and start numbering where the ‘old’ process left off.
So basically for my testing and development I wanted to add 5000 to the current item ID and put that into another field, we’ll call it Form Number.
In order to pull this off, I did the following:
  1. Create 2 hidden fields in InfoPath, I called them NumID and NumberToAdd. NumID will contain the ID of the item, NumberToAdd is the amount to add to the NumID – my default value is set at 5000.
  2. Set up the Submit button in the form to perform the following steps when clicked:
    1) Submit to the Form library
    2) Query a data connection that pulls the ID from my Form Library
    3) Set the NumID field to the ID of the item
    4) Set the Form Number field to NumID + NumberToAdd
    5) Submit to the Form library
    6) Close the form

The query data connection is simply a receive connection to my form lib, and it pulls the ID field only. Since I have the NumberToAdd field set at 5000, it adds 5000 to the current ID and I end up with the Form Number field showing a value of 5001, 5002, etc.

Pretty simple, but sometimes the simple things give me the most problems! Thanks again to Clayton and Saed for the assistance via Twitter!

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s