Autonumber repeating table rows in InfoPath 2010
Learn how you can use a formula in InfoPath to autonumber a repeating table by automatically assigning sequential numbers to rows of the repeating table on an InfoPath 2010 form. This solution also works for InfoPath browser forms in SharePoint.
In a previous article I wrote about how you can in InfoPath autonumber repeating table rows using VB.NET.
A best practice to keep in mind when designing InfoPath form templates is that you should always use code as a last resort, and instead give preference to solutions that make use of rules and formulas.
Code not only requires you to have programming skills or forces you to outsource your InfoPath form templates design to someone who has these skills, but it typically also involves more steps in particular when deploying InfoPath form templates to SharePoint.
So in this blog post, I’ll show you a way to use a formula to in InfoPath autonumber repeating table rows, so that you automatically get sequential numbers in a repeating table field whenever rows are inserted or deleted. By the way, this solution also works for InfoPath forms that are hosted in SharePoint and filled out through a browser.
This is what the final InfoPath autonumber repeating table form would look like in SharePoint:
Figure 1. Autonumber repeating table rows in InfoPath 2010.
You can in InfoPath autonumber repeating table rows as follows:
- In InfoPath Designer 2010, create a new Blank Form template.
- On the Home tab under the Controls group, click Repeating Table and add a repeating table with 3 columns to the form template.
- Right-click the first field (field1) in the repeating table and choose Change Control and then Calculated Value from the context menu that appears.
- With the first field (field1) still selected, click the Properties tab or double-click field1 to bring forward the Properties tab.
- On the Properties tab under the Properties group, click Default Value.
- On the Field or Group Properties dialog box on the Data tab under the Default Value section, click the formula button behind the Value text box.
- On the Insert Formula dialog box, select the Edit XPath (advanced) check box.
- On the Insert Formula dialog box, type the follow formula into the Formula text box:
count(../preceding-sibling::*) + 1
- On the Insert Formula dialog box, click Verify Formula to ensure that the formula does not contain any errors. Click OK to close the message box that says whether the formula contains or does not contain errors. Correct any errors if necessary.
- On the Insert Formula dialog box, click OK.
- On the Field or Group Properties dialog box, ensure that the Refresh value when formula is recalculated check box is selected, and then click OK.
- Save the InfoPath form template and publish it for example to a SharePoint form library.
Now whenever you insert or remove a row from the repeating table, the numbers in the first column of the repeating table are automatically recalculated and displayed sequentially in ascending order thereby creating an autonumbered repeating table in InfoPath.
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. The 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.