Tuesday, May 6, 2008

Auto Number for InfoPath Forms in a SharePoint Library

After not finding a solution to this problem, I decided to try some things.

You might find this solution interesting. I was trying to get an auto number without using a DB connection. I have seen a few solutions, for example at http://www.infopathdev.com/forums/ where the number is generated by a SQL Server Table, but that seemed a little complex for me to build in a day.

Here’s what I did:

Create a secondary data source that points to the SharePoint list and pick the custom field which I named "PONumber"











Add it to the form using a text box. InfoPath complains, but ignore errors upon publishing it.






Create a workflow that sets the field value after submit. This also insures a unique value since it is using the ID of the list. This workflow is set to start when an item is created.

















The String Builder lets you put in the ID Variable of the SharePoint list.









And heres the final product. I haven’t thought of any reason why this won’t work well, except the number at the end, in this case, is the year. That will have to be manually changed in 09 and a new form library will need to be created of you want to start out in 09 with “ARL-1-09”.

3 comments:

Eric said...

Paul - I'm trying to use your solution that you posted in the blog entry
above, and I've got it working, except for one thing - I can't add my custom
field to the Infopath form as a text box, only as a repeating text box. (I'm
using browser-compatible forms, if that is part of the problem.) Any idea
what I'm doing wrong?

Paul Houtz said...

If you drag the ID field into the form, you will get a repeating field. Then just take that text box and drag it out of the repeating region. That's where InfoPath give the error that it cannot store data correctly.

I only use browser forms on SharePoint 2007.

DKrout said...

Paul - I've attempted to use your solution but my workflow ends in an error everytime indicating that the document is checked out. How can I get the field to populate as soon as the form is opened so that the user knows what name to use when they save the form?