Skip Ribbon Commands Skip to main content
Help (new window)
Sign In
Navigate Up
Get Microsoft Silverlight
Install Silverlight plugin for a richer experience...
Blog Home |  Freeware |  Speaking |  About me

Setting up dynamic drop downs in the out of box SharePoint forms


A new feature in InfoPath 2010 is the ability to customize out of the box, auto-generated forms. Even if you choose the out of the box approach and later decide you need more functionality, you can customize those forms with InfoPath. This blog post walks you through the steps involved in customizing the out of the box forms. You'll also see how to setup dynamic drop downs in your form, where the values of the drop down are dependent upon another drop down's selection.

 

To get started, first create a SharePoint list or library, and onto that list add all the columns you need to track. You can do this through the List Settings and then Add a column option. After you have all your columns set up for your data requirements, edit the forms to suite your user interface requirements. When in the Ribbon, in the List tab, you can use the Customize List dropdown and choose Customize Form to launch InfoPath.

 

 

The example you're going to build involves a tasks list, and each task has an associated Project and Sub Project. What we want to do is change the lookup columns for these associated projects to be dynamic, so when you select a Project, the Sub Project dropdown will change its items based on what parent Project was selected. The figure below shows how the tasks form looks when it's first opened in InfoPath. Notice the Parent Project and Sub Project columns that you'll alter.

 

The Parent Project column is a lookup column to a separate list called Project Names. Sub Project is another lookup column to a second separate list called Sub Project Names. The Sub Project Names list has two columns, Title and Parent Project. Parent Project again is a lookup to the Project Names list. Before continuing, set up the two Project Names and Sub Project Names lists as previously described. Then add a Project Name lookup column and a Sub Project Name lookup column to a Tasks lists. Last, edit the out of the box form in InfoPath as shown in the figure.

 

To make the Sub Project dropdown in your tasks form dynamically, select its items based on what is selected in the Parent Project dropdown. First create a new data source for the Sub Project dropdown. The default data source for this dropdown only has two fields, Title and ID. Because you need to filter on the Parent Project column, add a new data source. Then filter that data source on the selected Parent Project. And last, set up a rule on the Parent Project dropdown to ensure the data source is updated each time the dropdown is changed. The following steps will walk you through this process:

 

STEP 1

While customizing the out of the box task edit form in InfoPath, set up a new data source for the sub project dropdown menu:

1) In the Data tab within the Ribbon in InfoPath, click the Data Connections button. Click the Add button to add a new data source.

2) Select the radio buttons to create a new data source that receives data. Click Next.

3) Choose to receive data from a SharePoint library or list. Click Next.

4) Type the URL to the SharePoint site that contains the Sub Project Names lists and then click Next and continue wizard in step 2.

 

STEP 2

Specify your list and columns to be included in the data source:

1) Select the list name that contains the data for your connection (in this case, Sub Project Names) and click Next.

2) Select the columns to include in the data source (in this case Title, Parent Project, and ID columns). Click Next twice.

3) Give the data source a name, like Sub Projects Filtered by Parent Project Selection. Click Finish to complete the data source wizard, and then Close.

4) Change the Sub Project dropdown to use this data connection instead of the default connection by right clicking on the dropdown and choosing Drop Down List Box Properties. Then change the Data Source dropdown menu to be the data connection that was created and finally click OK.

 

STEP 3

Filter the new data source on the selected parent project. In the entries box directly below the Data Source selection on the Sub Project dropdown, you'll see the XPath query that points to the data. Click the Select XPath button directly to the right of the text box (click the ellipses image). Follow these steps to set up the filter:

1) In the Select a Field or Group dialog box, click the Filter Data button and then click Add.

2) The first dialog box contains the fields in your custom data source. Select the Parent Project field. Leave the comparing field (middle dropdown) set to is equal to.

3) In the third dropdown, choose Select a field or group. Another dialog box will appear; change the Fields dropdown to Main to select the data that is represented on the form itself.

4) There are two sub folders: the queryFields folder will query fresh data, and dataFields folder contains the data on the form at the present time. Expand the dataFields folder.

5) Expand the sub folder containing the list item data. Select the Parent Project field. Click OK five times.

 

STEP 4

Now your Sub Project dropdown is correctly filtering its data based on what the Parent Project dropdown's selected value is set to. The last thing you need to do before you publish the form into our SharePoint tasks list is to set up a rule on the Parent Project dropdown. Each time the Parent Project dropdown's value is changed, you need to tell the Sub Project dropdown to update its items.

1) Right click the Parent Project dropdown, and under the Rules flyout, select Manage Rules.

2) Click the New dropdown in the Manage Rules tool bar, and select Action.

3) Give the rule a name, like Update Sub Project Dropdown.

4) Next to Run these actions click the Add dropdown and select Query for data.

5) In the Data Connection dropdown, select the custom data connection you created earlier. In this case, select Sub Projects Filtered by Parent Project Selection and then click OK.

 

That's it! Now all that's left is to publish the form into your tasks list. Under the File menu in the Info tab, click Quick Publish. Now when you go to create a new task in your tasks list, the Sub Projects dropdown will be dynamically populated based on what Parent Project is selected!

 

 

Only Positive Integers Allowed Error

If you get an error that says Only Positive Integers Allowed, you're trying to save a string into a column that is expecting a number. Most likely the Sub Project drop down's value is set to a string but because the column is a lookup, it needs to be a number instead. To fix this error, right click on the Sub Project dropdown and choose Dropdown list properties. Then underneath Entries, change the Value from d:Title to d:ID. After you republish the form, the form should start saving properly.

 

Phil