1,627 articles and 11,821 comments as of Monday, July 12th, 2010

Thursday, July 8, 2010

SharePoint: Extending the DVWP – Part 17: User-Managed Dropdowns – Creating a Relationship list

Author: Jim Bob Howard

Whether working with cities and states, sizes and colors, jobs and locations, etc., the ability to cascade—or limit—the choices of one dropdown based on the selection in another is a requirement for usability.

But before we start cascading our dropdown selections, we need to consider the data that will be in each one and the relationship between them. In many cases (sizes/colors; jobs/locations), it’s also imperative that a content owner be able to modify the selections in a list. The standard choice column type isn’t the best option for this because the data is "hidden" within the column definition.

Using a lookup column makes much more sense. And that’s what we need if we’re going to cascade our dropdowns.

Note: All of the content and thought process for this article arose from a discussion with Marc Anderson in January 2010 on the discussion forums for his jQuery Library for SharePoint Web Services (SPServices). You can read the entire conversation here.

Site Columns for Cascading dropdowns

What if the dropdown option choices are managed by one group, but used by another? For example, HR may need a strict definition of job titles, but a manager may be the one who is controlling the list of employees that use that title. So, how do we "reuse" data that might be useful company-wide?

Answer: Use site columns, which I discussed in the last article in this series.

Assuming you followed the advice in the last section, of the Countries and States, you already have the two data lists. You will need the related data to be stored in the respective lists before setting up the relationships.

It’s All in the Relationships

Cascading dropdowns depend on the relationship between the data in the two dropdown lists. So, first we create a list for each of the sets of data (e.g. Countries and States); then we set up a list that describes the relationship between the two.

Let’s now set up the relationship list.

  1. Click Site Actions -> Create

  2. From main site, click Site Actions -> Create

  3. Under Custom Lists, click Custom List in Datasheet View

  4. For this example, I’m going to relate Countries and States, so I’ll name it RELCountryStates

  5. Creating the relationship list with a name that contains no spaces will help us down the road

    Notice that I don’t want this to show up in the Quick Launch (your requirements may vary).

    Give your list a name without spaces for now; this will set its ’static name.’ We’ll update the ‘display name’ in the next step.

  6. You’ll now see that we have a list in Datasheet view. Let’s modify it, then we’ll load the data. Click Settings -> List Settings

  7. RELCountryStates – Click Settings -> List Settings

    1. Change the name
      1. Under General Settings, click Title, description and navigation

      2.  Change the Name to something descriptive (e.g. Country-State Relationships)

      3. Set the ‘display name’ of the List

      4. Click the Save button
    2. Remove attachments
      1. Under General Settings, click Advanced settings

      2. Under Attachments, click Disabled

      3. Disable attachments

      4. Click the OK button (twice)
    3. Add site columns
      1. Click Add from existing site columns

      2. Click both site columns and click the Add > button

      3. If you assign your relationship site columns to a common group, they’re easy to find

      4. Leave Add to default view checked and click OK
  8. Click the list name in the breadcrumbs to return to the datasheet view

  9. The breadcrumb will take you back to the datasheet view


    Datasheet view with site columns Countries and States

  10. You will need the related data to be stored in the respective lists before setting up the relationships. If you haven’t done that already, do it now. (Last time, I shared a method for quickly loading data in the lists used by your site columns.)
  11. Now, all you need to do is add a record for every State in your site column list and relate it to its Country.

  12. The site columns now have dropdowns for selecting only from valid values.

  13. Loading these one by one will take forever, so we’re going to do something similar to what we did when we loaded the site column lists, by pasting the entire list into this table. But we’re going to have a bit of an issue with the Title column, which is required by default. Here are our options:
    1. We can make the Title optional (and hide it from view, if desired)
    2. We can make it optional and create a workflow that concatenates the site columns to make up a unique Title. (Not recommended.)
    3. We can use Excel to create our entire Country-State Relationships table and paste the entire thing in here.

Next time, I’ll show you a quick way to load the data using the first option; then I’ll walk through it using Excel.

Author: Jim Bob Howard

Jim Bob Howard is a web designer / webmaster in the healthcare industry. He has been working with SharePoint since March 2009 and enjoys sharing what he has learned. He is a moderator and frequent contributor to Stump the Panel, and answers SharePoint questions on Twitter (@jbhoward) and via email ([email protected]).

View all entries in this series: Extending the DVWP»
Entries in this series:
  1. SharePoint: Extending the DVWP - Part 1: Layout Enhancement - Rearranging Columns - Default and Edit Templates
  2. SharePoint: Extending the DVWP - Part 2: Layout Enhancement - Rearranging Columns - Insert Template
  3. SharePoint: Extending the DVWP – Part 3: Getting it All on One Line - DVWP Function Action Links
  4. SharePoint: Extending the DVWP – Part 4: Turning DVWP Action Links into Buttons
  5. SharePoint: Extending the DVWP – Part 5: Doing Stuff Before Save on Submit - PreSaveAction()
  6. SharePoint: Extending the DVWP – Part 6: Examining the Form Action Links
  7. SharePoint: Extending the DVWP – Part 7: Creating a Form Action Workflow
  8. SharePoint: Extending the DVWP – Part 8: Creating a Form Action Workflow - The After Math
  9. SharePoint: Extending the DVWP – Part 9: Oops! Failed Setting Processor Stylesheet
  10. SharePoint: Extending the DVWP – Part 10: Passing Workflow Variables to a Form Action Workflow
  11. SharePoint: Extending the DVWP – Part 11: Getting More Form Fields to the Workflow
  12. SharePoint: Extending the DVWP – Part 12: Adding More Form Fields from the Data
  13. SharePoint: Extending the DVWP – Part 13: Putting PreSaveAction() to Work – Creating Variables
  14. SharePoint: Extending the DVWP – Part 14: Putting PreSaveAction() to Work with jQuery
  15. SharePoint: Extending the DVWP – Part 15: User-Managed Dropdowns with Site Columns
  16. SharePoint: Extending the DVWP – Part 16: User-Managed Dropdowns - Loading Data
  17. SharePoint: Extending the DVWP – Part 17: User-Managed Dropdowns – Creating a Relationship list
 

Please Join the Discussion

One Response to “SharePoint: Extending the DVWP – Part 17: User-Managed Dropdowns – Creating a Relationship list”
  1. Greg says:

    Hi Jim,
    I actualy tested the SPServices cacading dropdows from Marc on SP2010 just yesterday!
    Creating a 3rd ‘Relationship’ List is a great trick – however, I don’t see yet what the exact advantage of it is yet?
    The way I had done it was lookup from 1 List towards the other at the item level and then fill out the look up column in the child list with the correct lookup using the Data view.
    Can’t wait to see how you tie it with the DVWP.

    Have you tried SP2010 yet?

    Greg


Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!