InfoPath 2010 previous next navigation on a SharePoint list
Learn how you can create an InfoPath 2010 form template with previous and next buttons for navigation through items of a SharePoint list that has been added as a secondary data source to the form template.
You have a SharePoint 2010 list and you want to be able to navigate through the items in the list one by one by clicking on previous and next buttons.
InfoPath does not allow you to filter rows or sections that are bound to a repeating group in a secondary data source, as is the case when you create a receive data connection to a SharePoint list, so you must find a workaround.
You can create a solution that combines a hidden field, formulas, and conditional formatting to be able to filter data from a secondary data source for a SharePoint list and thereby create previous next navigation functionality in InfoPath 2010.
To create previous next navigation in InfoPath 2010 on SharePoint list items:
- In InfoPath, create a new Blank Form template.
- Add an InfoPath 2010 SharePont list data connection. Ensure that the check box Automatically retrieve data when form is opened is selected when you create the data connection. This article uses a SharePoint 2010 list named OfficeApplications and has imported 3 columns named: ID, Title, and Color. The secondary data source for this SharePoint list is shown in the following figure.
Figure 1. Secondary data source of a SharePoint list in InfoPath 2010.
- Add 3 Text Box controls named id, title, and color to the InfoPath form template.
- Add 2 Button control to the form template and change their labels to Previous and Next, respectively.
- Add an InfoPath hidden field named position to the Main data source of the InfoPath form.
- Design an InfoPath form template similar to the one shown in the following figure.
Figure 2. InfoPath 2010 form template for previous next navigation.
- Click the id text box to select it.
- On the Properties tab, click Default Value.
- On the Field or Group Properties dialog box, click the formula button behind the Value text box.
- On the Insert Formula dialog box, click Insert Field or Group.
- On the Select a Field or Group dialog box, select the secondary data source to the SharePoint list from the Fields drop-down list box, expand the dataFields node, select the ID node, and then click Filter Data.
- On the Filter Data dialog box, click Add.
- On the Specify Filter Conditions dialog box, select Select a field or group from the first drop-down list box.
- On the Select a Field or Group dialog box, select Main from the Data source drop-down list box, select the position field, and then click OK.
- On the Specify Filter Conditions dialog box, select The expression from the first drop-down list box and then change the expression in the text box from:
xdXDocument:get-DOM()/my:myFields/my:position = ""
and click OK.
- On the Filter Data dialog box, click OK.
- On the Select a Field or Group dialog box, click OK.
- On the Insert Formula dialog box, select the Edit XPath (advanced) check box, and change the expression from
- Click Verify Formula to check that the formula does not contain any errors, and then click OK.
- On the Field or Group Properties dialog box, click OK.
- Repeat steps 7 through 20 for the title and color fields. Tip: You can also copy the expression from step 18, change the field name in the expression from ID to Title and from ID to Color, and then paste it in the Default Value field for the title and color fields.
- Right-click the position field in the Main data source and select Properties from the drop-down menu.
- On the Field or Group Properties dialog box, enter a 1 in the Default Value text box, and click OK.
- Add an Action rule on the Previous button with an action that says:
Set a field's value: position = position - 1
- Add an Action rule on the Next button with an action that says:
Set a field's value: position = position + 1
- Add a Formatting rule on the Previous button with a Disable this control formatting and a condition that says:
position = 1
- Add a Formatting rule on the Next button with a Disable this control formatting and a The expression condition that says:
number(xdXDocument:get-DOM()/my:myFields/my:position) >= count(xdXDocument:GetDOM("OfficeApplications")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID)
Tip: Copy the expressions you constructed earlier in steps 15 and 18. Remove the filter from the expression from step 18 and add the count() function around it. Then separate the two expressions with the >= sign. What the final expression does is check whether the value of the position field is greater than or equal to the total amount of items in the SharePoint list.
- Save the form template and test it.
Now when the form opens, the first item of the SharePoint list is shown and the Previous button is disabled.
Figure 3. Previous next navigation of a SharePoint list with InfoPath 2010.
As you click the Next button and navigate through the items of the SharePoint list, the Previous button is enabled. When you reach the final item in the SharePoint list, the Next button is disabled. When you click and navigate backwards through the SharePoint list items, the Next button is enabled again, and once you reach the first item, the Previous button is disabled again.
Related InfoPath Articles:
- Add a data connection to a SharePoint 2010 list
- How to create a 'hidden' field in InfoPath
- Sequential database table record navigation
- Auto-fill fields in InfoPath from a drop-down list box selection and secondary data source
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 of S.Y.M. Wong-A-Ton. 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, S.Y.M. Wong-A-Ton.