Friday, November 9, 2012

Cascading dropdown lists in SharePoint 2010


Today I am going to explain you how to create a list with filtered lookup columns, based on information in previous columns. Check out SharePoint Cascaded Lookup from SharePointBoost.
Image from SharePointBoost
The software looks great. I haven’t tried it, but it does offer some great extra functionality.
Unfortunately, this piece of software is very expensive for small companies that only need this for a single form on SharePoint.
So I am going to show you how to create such a list without the need of buying this piece of software. I covered it into a lot of steps, but no programming is needed. The only things you need, are a SharePoint 2010 environment, InfoPath 2010 and this tutorial :D !
For this small tutorial, I will create a simple room-reservation list for a company existing out of multiple physical buildings. I will not explain about how to create a reservation system, I only use it as a example to show you how to filter data based on a previous selected item.
The result of this tutorial will be a form where you can select a physical location. After you made your selection, only those rooms for that building will be shown.
Again, i covered this into a lot of steps. But after you have done this a couple of times, you do not need expensive software and you can create filtered lookup forms yourself!

  1. Create a Custom list called ‘buildings’.
    A Custom list is created with no extra columns except for ‘title’. We leave it like that.
  2. Add buildings to the list: ‘Building A’, ‘Building B’ and ‘Building C’.
  3. Create another Custom list called ‘rooms’.
  4. Go to the list settings of ‘rooms’ and click on ‘create column’. Create a Lookup column called ‘Building’.
    Require that the column contains information.
    Get information from: ‘Buildings’,  in this column: ‘Title’
  5. Add some rooms to this list. I created multiple rooms at each location.
You have now created the needed lists and filled it with data, but we still need to create the room reservation form.
  1. Again, create a new Custom list called ‘reservations’.
  2. Click on ‘Create column’ and create a Lookup column called ‘Building’. Get information from: ‘buildings’,  in this column: ‘Title’
  3. Repeat step 2, but this time create a Lookup column called ‘Room’. Get information from: ‘rooms’,  in this column: ‘Title’
  4. Use Internet Explorer: Open the list settings for ‘reservations’ and click on ‘Form settings’.
    You will see a label with the text ‘Customize the current form using Microsoft InfoPath’. Click OK.
  5. The Reservations form will now be opened in InfoPath 2010.
  6. Right click on the Building field, and select properties.
    Select ‘Get choices from an external data source’ and click ‘Add…’.
    Create a connection with the following settings:
    - New connection, receive data
    - Receive data from: SharePoint library or list
    - select ‘buildings’ library
    - select the ‘id’ and ‘title’ column
    - do not check the box for making a copy of the data
    - check the box that asks for automatically retrieving data when the form is opened. Save the external data source as ‘buildings1′.
  7. At value, choose ‘ID’ and at display name, choose ‘Title’
  8. Right click on the Room field, and select properties.
    Select ‘Get choices from an external data source’ and click ‘Add…’.
    Create a connection with the following settings:
    - New connection, receive data
    - Receive data from: SharePoint library or list
    - select ‘rooms’ library
    - select the ‘id’, ‘title’ and ‘building’ column
    - do not check the box for making a copy of the data
    - do not check the box that asks for automatically retrieving data when the form is opened. Save the external data source as ‘rooms1′.
  9. At value choose ‘id’, choose ‘Title’ for  the display name.
You are not done yet, but almost there! A little break here, to tell you what you have done in the last few steps. You created 2 data connections, retrieving data from the SharePoint lists ‘buildings’ and ‘rooms’. The data connection for buildings will load its data into the buildings form when the form is being opened. The other one won’t. Check it out, press ctrl+shift+Q for a fast publish and add a new item to the registration list. If all went well you will see something like this:

The Room listbox should not yet contain any data.
Now we are going to execute the final steps. In these steps you will create a filter. This filter will show only rooms for the building you selected in the field above.
  1. Click on the xPath button at the properties dialog of Room next to ‘Entries’.
    Click on the ‘Filter data’ button.
  2. Click on ‘Add’.
    In the first column, choose ‘select a field or group’. A window pops up, choose advanced view.
    - Select the ‘main’ datasource, click on ‘dataFields’ and select ‘Building’.In the second column, choose ‘equals’.In the third column, choose ‘select a field or group’. Agan a window pops up, choose advanced view.
    - Select the ‘rooms’ datasource, click on ‘dataFields’ and select ‘Building’.
    Click OK
  3. The filter will now look like ‘Building equals Building’. Now close all property dialogs.
  4. Select the building column and click on ‘Add Rule’. Select the query action when the field is changed.

    Now choose the data connection ‘rooms1′ and click OK.
  5. Again, click Building and make a new rule: When the field is being changed, set a value for a field.

    Choose field ‘Room’ and leave value empty.
Finally! We are done. Fast publish the form to SharePoint again by pressing ctrl+shift+Q.
Now if you carefully executed all steps above, you will see a form like this:

Notice that only rooms will be shown that are located in that specific building.

No comments:

Post a Comment

SharePoint - Cannot convert a primitive value to the expected type 'Edm.Double'. See the inner exception for more details If y...

Ad