Populating InfoPath Drop down with SharePoint List Data
 
 
In this article, we will populate a drop down in InfoPath form with data retrieved from a SharePoint list.

We will continue using the user registration form that we created in one of the previous articles. The country field, which we added as a text box, will be converted to a drop down box.

1. We will need a list on the SharePoint that will hold all country names. Create a list in SharePoint and add some countries. Name the list "Countries". Use "Title" field to store the country names.



2. Open the user registration form in InfoPath editor.

3. Right-click the "Country" text box and move your mouse to "Change To" option, that will open another menu. Select "Drop-Down List Box". This will convert the text box into a drop down box.



4. Right-click the drop down and select "Drop-Down List Box Properties"



5. In "List box entries", select the third option "Look up values from an external data source".

6. Click the "Add" button.

7. In the "Data Connection Wizard", select "Create a new connection to:". Sub-option "Receive data" will automatically be selected. "Submit data" will be disabled, this is because you cannot submit data to a drop down. Click "Next:.



8. Select "SharePoint library or list" from the options and click "Next:.



9. Enter the SharePoint site collection URL and click "Next".

10. You will be shown all the lists on the server. Select "Countries" list and click "Next"

11. You will see a list of fields. We saved country names in "Title" field, so select "Title" field and click "Next".

12. Check "Store a copy of the data in the form template" option and click "Next".

13.You can change the name of data connection in this step. The default name is "Countries" which is the list name. Make sure the checkbox "Automatically retrieve data when form is opened" is checked and click "Finish".

14. You will be back in the "Drop-Down List Box Properties". Click the "Select XPath" button.



15. Expand "dataFields" node. Select ":Title" node. You will also see "Filter Data..." button. It filters data retrieved from the list. It's a great feature but does not work in web enabled forms. In web forms, we have to filter data programmatically. Click "OK".



16. Had there been multiple columns in the list, we could have selected a value different from the display name. Yes, you can select different list columns to be used as drop down value and drop down display name. Because we are only using one field, therefore, only "Title" field is selected in both "Value" and "Display name" fields.



17. Check "Show only entries with unique display names" option. This is in fact not required here because we know the names will be unique but if the list has duplicate names, then this option allows us to select unique names from the list. Click OK.



18. Publish the form and test the functionality. Open the form, the "Country" drop down will show all countries form the list.



There is a draw back to this method. If you deploy this form on a different server. The functionality will break because the data connection will still be pointing to the list on the development machine. There are other methods to achieve correct behavior. One of them is to do it programmatically. We will discuss it in another article.

Download completed InfoPath form and application code