Welcome!

Blog Feed Post

Deploying Relational Lists using CAML in SharePoint 2010

One of my favorite new features in SharePoint 2010 is the ability to have lists relate to each other and the fact that you can maintain referential integrity.  Now, I am sure there are at least 50 posts out there already that show you how to do this using the UI.  The UI is great, but you are a developer and that means you might want to actually deploy these lists elsewhere someday.  Now I have to admit, using the save site as template feature is great for moving sites and content around but you may want a more granular deployment of a pair of lists in a single feature.  The cool thing is the save site as template feature is extremely useful for discovering the underlying CAML to build things in SharePoint which is how I discovered relational lists work today.  This post has some great screenshots of how to export a site template as a wsp.

For today’s example, I have a list of categories and a list of products.  The products list has a lookup column which references the categories list.  Here is what the products list looks like.

RelationalLists

On this view, you can see that I am linking to the Categories list and I am displaying the Id and Description from that list.  Here is how my lookup column is defined.

RelationalListsLookupColumn

Creating a list with CAML in SharePoint 2010 is really not much different than in previous versions.  In order to set up this lookup column, we need to look at the Schema.xml of the Products list.  It turns out that the column that the user chooses is still a lookup column but so are the additional fields.  They just have additional attributes defined.  Let’s look at the definition of the lookup column the user interacts with first.

<Field Type="Lookup" DisplayName="Category" Required="FALSE" EnforceUniqueValues="FALSE" List="Lists/Categories" ShowField="Title" UnlimitedLengthInDocumentLibrary="FALSE" Indexed="TRUE" RelationshipDeleteBehavior="Cascade" ID="{c59b5e18-54c2-408a-a231-b88c3e939e90}" SourceID="{$ListId:Lists/Products;}" StaticName="Category" Name="Category" RowOrdinal="0" />

I got this schema by doing an export as mentioned above.  There are a few things you might notice here.  The list name and SourceID refer to the lists by URL instead of a hardcoded Id.  The value of Indexed is also set to true.  This is because relational lists require indexed columns.  You also get prompted to index the column when you set it up through the UI.  The last thing to note is the RelationshipDeleteBehavior attribute.  It can have a value of Cascade, Restrict, or none.  This corresponds to relationship behavior you see in the UI screenshot above.

The additional fields from the parent list are also lookup fields.   They just have a few key differences.

<Field Type="Lookup" DisplayName="Category:ID" List="Lists/Categories" WebId="8c918dd2-ef1f-4822-b3d2-f587d622d203" ShowField="ID" FieldRef="c59b5e18-54c2-408a-a231-b88c3e939e90" ReadOnly="TRUE" UnlimitedLengthInDocumentLibrary="FALSE" ID="{2264d6b5-7001-40e1-b295-236b9965c833}" SourceID="{$ListId:Lists/Products;}" StaticName="Category_x003a_ID" Name="Category_x003a_ID" />

<Field Type="Lookup" DisplayName="Category:Description" List="Lists/Categories" WebId="8c918dd2-ef1f-4822-b3d2-f587d622d203" ShowField="Description" FieldRef="c59b5e18-54c2-408a-a231-b88c3e939e90" ReadOnly="TRUE" UnlimitedLengthInDocumentLibrary="FALSE" ID="{a0ab273e-5989-42ba-950d-3add1c1025e0}" SourceID="{$ListId:Lists/Products;}" StaticName="Category_x003a_Description" Name="Category_x003a_Description" />

First, the FieldRef attribute has the Id of the first lookup field we defined.  This is what ties them together.  The second thing is that the ShowField attribute refers to the name of the field in the lookup list.  The last thing to note is that they are marked as readonly.  One more thing to point out is that the static name is encoded with x003a which is the color you see in the DisplayName.  This is also used in the FieldRef elements you will also have on any ConentType element thats uses these fields in your schema.xml.  For example.

<FieldRef ID="{c59b5e18-54c2-408a-a231-b88c3e939e90}" Name="Category" Required="FALSE" />

<FieldRef ID="{2264d6b5-7001-40e1-b295-236b9965c833}" Name="Category_x003a_ID" ReadOnly="TRUE" />

<FieldRef ID="{a0ab273e-5989-42ba-950d-3add1c1025e0}" Name="Category_x003a_Description" DisplayName="Category:Description" ReadOnly="TRUE" />

You might not see much value in this post yet, but I think you might in the future.  The tools to work with SharePoint have improved greatly, but you still will need to work with some CAML from time to time I believe.  You may not be building it from scratch any more, but it is still good to know your way around it.  As a developer I often get frustrated when I run into posts showing how to do something through the UI when I really need to know how to build something declaratively or programmatically.  Hopefully this will be helpful.

Read the original blog entry...

More Stories By Corey Roth

Corey Roth, a SharePoint Server MVP, is an independent consultant specializing in Cloud technologies such as Azure and Office 365. He also specializes in mobile development. Corey serves as the product manager for two cloud-first mobile app platforms: BrewZap and HappenZap.

Latest Stories
Whenever a new technology hits the high points of hype, everyone starts talking about it like it will solve all their business problems. Blockchain is one of those technologies. According to Gartner's latest report on the hype cycle of emerging technologies, blockchain has just passed the peak of their hype cycle curve. If you read the news articles about it, one would think it has taken over the technology world. No disruptive technology is without its challenges and potential impediments t...
Hackers took three days to identify and exploit a known vulnerability in Equifax’s web applications. I will share new data that reveals why three days (at most) is the new normal for DevSecOps teams to move new business /security requirements from design into production. This session aims to enlighten DevOps teams, security and development professionals by sharing results from the 4th annual State of the Software Supply Chain Report -- a blend of public and proprietary data with expert researc...
Lori MacVittie is a subject matter expert on emerging technology responsible for outbound evangelism across F5's entire product suite. MacVittie has extensive development and technical architecture experience in both high-tech and enterprise organizations, in addition to network and systems administration expertise. Prior to joining F5, MacVittie was an award-winning technology editor at Network Computing Magazine where she evaluated and tested application-focused technologies including app secu...
DXWorldEXPO LLC announced today that Nutanix has been named "Platinum Sponsor" of CloudEXPO | DevOpsSUMMIT | DXWorldEXPO New York, which will take place November 12-13, 2018 in New York City. Nutanix makes infrastructure invisible, elevating IT to focus on the applications and services that power their business. The Nutanix Enterprise Cloud Platform blends web-scale engineering and consumer-grade design to natively converge server, storage, virtualization and networking into a resilient, softwar...
DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
Having been in the web hosting industry since 2002, dhosting has gained a great deal of experience while working on a wide range of projects. This experience has enabled the company to develop our amazing new product, which they are now excited to present! Among dHosting's greatest achievements, they can include the development of their own hosting panel, the building of their fully redundant server system, and the creation of dhHosting's unique product, Dynamic Edge.
This session will provide an introduction to Cloud driven quality and transformation and highlight the key features that comprise it. A perspective on the cloud transformation lifecycle, transformation levers, and transformation framework will be shared. At Cognizant, we have developed a transformation strategy to enable the migration of business critical workloads to cloud environments. The strategy encompasses a set of transformation levers across the cloud transformation lifecycle to enhance ...
Your job is mostly boring. Many of the IT operations tasks you perform on a day-to-day basis are repetitive and dull. Utilizing automation can improve your work life, automating away the drudgery and embracing the passion for technology that got you started in the first place. In this presentation, I'll talk about what automation is, and how to approach implementing it in the context of IT Operations. Ned will discuss keys to success in the long term and include practical real-world examples. Ge...
The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
So the dumpster is on fire. Again. The site's down. Your boss's face is an ever-deepening purple. And you begin debating whether you should join the #incident channel or call an ambulance to deal with his impending stroke. Yes, we know this is a developer's fault. There's plenty of time for blame later. Postmortems have a macabre name because they were once intended to be Viking-like funerals for someone's job. But we're civilized now. Sort of. So we call them post-incident reviews. Fires are ne...
CloudEXPO New York 2018, colocated with DevOpsSUMMIT and DXWorldEXPO New York 2018 will be held November 12-13, 2018, in New York City and will bring together Cloud Computing, FinTech and Blockchain, Digital Transformation, Big Data, Internet of Things, DevOps, AI and Machine Learning to one location.
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
The digital transformation is real! To adapt, IT professionals need to transform their own skillset to become more multi-dimensional by gaining both depth and breadth of a wide variety of knowledge and competencies. Historically, while IT has been built on a foundation of specialty (or "I" shaped) silos, the DevOps principle of "shifting left" is opening up opportunities for developers, operational staff, security and others to grow their skills portfolio, advance their careers and become "T"-sh...
ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of computational needs for many industries. Their solutions provide benefits across many environments, such as datacenter deployment, HPC, workstations, storage networks and standalone server installations. ICC has been in business for over 23 years and their phenomenal range of clients include multinational corporations, universities, and small busines...