Paul Galvin's (old) SharePoint space [SharePoint

Just another WordPress.com site

Implementing Master / Detail Relationships Using Custom Lists

Forum users frequently as questions like this:

> Hello,
>
> Please tell me if there are any possibilities to build a custom list with
> master and detail type (like invoices) without using InfoPath.
>

SharePoint provides some out of the box features that support kinds of business requirements like that.

In general, one links two lists together using a lookup column.  List A contains the invoice header information and list B contains invoice details.

Use additional lists to maintain customer numbers, product numbers, etc.

Use a content query web part (in MOSS only) and/or a data view web part to create merged views of the lists.  SQL Server Reporting Services (SRS) is also available for the reporting side of it.

However, there are some important limitations that will make it difficult to use pure out-of-the-box features for anything that is even moderately complex.  These include:

  • Size of related lookup lists vs. "smartness" of the lookup column type.  A lookup column type presents itself on the UI differently depending on whether you’ve enabled multi-select or not.  In either case, the out-of-the-box control shows all available items from the source list.  If the source list has 1,000 items, that’s going to be a problem.  The lookup control does not page through those items.  Instead, it pulls all of them into the control.  That makes for a very awkward user interface both in terms of data entry and performance.
  • Lookups "pull back" one column of information.  You can never pull back more than one column of information from the source list.  For instance, you cannot select a customer "12345" and display the number as well as the customer’s name and address at the same time.  The lookup only shows the customer number and nothing else.  This makes for an awkward and difficult user interface.
  • No intra-form communication.  I’ve written about this here.  You can’t implement cascading drop-downs, conditionally enable/disable fields, etc. 
  • No cascading deletes or built-in referential integrity.  SharePoint treats custom lists as independent entities and does not allow you to link them to each other in a traditional ERD sense.  For example, SharePoint allows you to create two custom lists, "customer" and "invoice header".  You can create an invoice header that links back to a customer in the customer list.  Then, you can delete the customer from the list.  Out of the box, there is no way to prevent this.  To solve this kind of problem, you would normally use event handlers.

It may seem bleak, but I would still use SharePoint as a starting point for building this kind of functionality.  Though there are gaps between what you need in a solution, SharePoint enables us to fill those gaps using tools such as:

  • Event handlers.  Use them to enforce referential integrity.
  • Custom columns: Create custom column types and use them in lieu of the default lookup column.  Add paging, buffering and AJAX features to make them responsive.
  • BDC.  This MOSS-only feature enables us to query other SharePoint lists with a superior user interface to the usual lookup column.  BDC can also reach out to a back end server application.  Use BDC to avoid replication.  Rather than replicating customer information from a back end ERP system, use BDC instead.  BDC features provide a nice user interface to pull that information directly from the ERP system where it belongs and avoids the hassle of maintaining a replication solution.

    BDC is a MOSS feature (not available in WSS) and is challenging to configure. 

  • ASP.NET web form: Create a full-featured AJAX-enabled form that uses the SharePoint object model and/or web services to leverage SharePoint lists while providing a very responsive user interface.

The last option may feel like you’re starting from scratch, but consider the fact that the SharePoint platform starts you off with the following key features:

  • Security model with maintenance.
  • Menu system with maintenance.
  • "Master table" (i.e. custom lists) with security, built-in maintenance and auditing.
  • Search.
  • Back end integration tools (BDC).

If you start with a new blank project in visual studio, you have a lot of infrastructure and plumbing to build before you get close to what SharePoint offers.

I do believe that Microsoft intends to extend SharePoint in this direction of application development.  It seems like a natural extension to the existing SharePoint base.  Microsoft’s CRM application provides a great deal of extensibility of the types needed to support header/detail application development.  Although those features are in CRM, the technology is obviously available to the SharePoint development team and I expect that it will make its way into the SharePoint product by end of 2008.  If anyone has an knowledge or insight into this, please leave a comment. 

</end>

Advertisements

4 responses to “Implementing Master / Detail Relationships Using Custom Lists

  1. David December 24, 2007 at 8:48 pm

    You can create a Content Type for Invoice header based on the Folder Content Type and then create another Invoice Content Type and add both to a SharePoint list. This in effect creates a Parent/Child relationship which will allow you to create multiple Invoices based on the Invoice Content Type that live under the Invoice Header Content Type which gives you and instant relationship between the two items and if the Invoice Header list item is deleted all the child Invoice items within that Folder will be deleted. You can also specify that a Content Type only be available from within a certain Folder. This approach is similar to how the discussion library works and is very helpful for this type of relationship between items. Event handlers and code will help with some other limitations but overall a quick easy solution.

  2. Michael December 25, 2007 at 12:41 am

    It\’s a bit of a kludge but I use an ASP.Net dropdown which shadows the lookup "dropdown" generated by SharePoint. I point the ASP.Net dropdown to a datasource based on the list containing the lookup item, allowing me to use the ID field as the value and the column of my choice as the display text. I do not bind the ASP.Net dropdown to the lookup list field because it generates server-side errors.On page load I use javascript to assign the correct value to the ASP.Net dropdown, and then attach onchange events to that dropdown to assign new values to the corresponding SharePoint lookup dropdown. I actually hide the row containing the SharePoint dropdown.One last thing — because of the way SharePoint renders goofy lookup dropdowns when the number of items gets past 20 I use custom wrapper object to get/set the dropdown value. I have a blog post detailing that process here:http://www.idiotsyncrasies.com/2007/12/lookup-list-dropdowns-in-sharepoint.aspxCheers,Michael

  3. Raghu February 6, 2008 at 10:19 am

    I am creating Parent/Child realationship by using two content types and custom list as explained in the above commnet. But I have a problem; I need to make Item content type unavailable at Folder level and Folder content type unavailable at item level. Please guide me on this one. Thanks…
     
     

  4. Paul March 19, 2009 at 6:41 am

    Raghu, I don\’t think there\’s any easy way to do that. I would focus on training your users when to use which one of them and maybe give them a hint with the name of the content type itself. I don\’t think you can really nail this one down, technically.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: