December 24
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>