Tuesday, February 07, 2012

AutoNumbering in InfoPath forms when submitted to a SharePoint Library

You can accomplish this functionality as follows:





  1. In SharePoint, create a form library to submit your forms to.


  2. In InfoPath, create a new (browser-compatible) InfoPath form template.


  3. Add a Text Box control to the form template and name it autonumber.


  4. On the Tools menu, click Data Connections.


  5. On the Data Connections dialog box, click Add, and create a Receive data connection to the SharePoint library that you created in step 1. In step 5 of the data connection wizard, uncheck all fields and then check the ID field. In the last step of the data connection wizard, uncheck Automatically retrieve data when form is opened, name the data connection RetrieveIDs, and click Finish.


  6. On the Data Connections dialog box, click Add, and create a Submit data connection to the SharePoint library that you created in step 1. In step 3 of the data connection wizard, click the formula button behind the File name field.


  7. On the Insert Formula dialog box, type max( and then click Insert Field or Group.


  8. On the Select a Field or Group dialog box, select RetrieveIDs from the Data source drop-down list box, expand all the nodes, click ID, and then click OK.


  9. On the Insert Formula dialog box, type ) + 1 and click OK.


  10. On the Data Connection Wizard dialog box, the expression in the File name field should resemble: max(@ID) + 1


  11. On the Data Connection Wizard dialog box, click Next, name the data connection Main submit, and then click Finish.


  12. On the Data Connections dialog box, click Close.


  13. On the Tools menu, click Submit Options.


  14. On the Submit Options dialog box, check the Allow users to submit this form checkbox, select the Perform custom actions using rules option, click Advanced, select Close the form from the After submit drop-down list box, and then click Rules.


  15. On the Rules dialog box, click Add.


  16. On the Rule dialog box, add an Action that says: Query using data connection: RetrieveIDs


  17. On the Rule dialog box, add a second Action that says: Set a field's value: autonumber = max(@ID) + 1 Note: @ID is selected from the RetrieveIDs secondary data source in the same way you selected it in step 8.


  18. On the Rule dialog box, add a third Action that says: Submit using data connection: Main submit


  19. Click OK when closing all dialog boxes that are currently open.


  20. Publish the form template to the library you created in step 1.



You should now be able to fill out a form and submit it. The next available number in the form library will be automatically saved in the autonumber field of the form when the form is submitted and this number will also be used for the Name of the form. This solution works for both forms that are filled out through the InfoPath client application as well as those that are filled out through the browser.

No comments: