It’s easy to configure an External List with Business Connectivity Services (BCS) in SharePoint Foundation 2010
Posted
Tuesday, February 2, 2010 5:02 PM
by
CoreyRoth
One of my favorite features in SharePoint 2010 is External Lists. If you haven’t heard by now, the MOSS 2007 Business Data Catalog (BDC) has become Business Connectivity Services (BCS) in SharePoint 2010. The ever better part is that it is included in SharePoint Foundation and does not require SharePoint Server. One new concept that we get from this is the External List. To the end user, these look like regular lists in SharePoint, however they really are reaching out to external systems such as databases and web services. Whereas the BDC only “officially” supported read operations, the BCS supports full CRUD operations on your external data source.
The title of the article mentions how easy it is to set up. As you will see shortly, it really is quite easy using SharePoint Designer. In fact, if you have a database table, you can have it exposed in SharePoint in under 10 minutes. If you worked with the BDC before, you know that we had to manipulate huge XML files that represented the application definition. We relied on third party tools to make this easier, but it was never a clean experience until now. Before we get started with SharePoint Designer though, first make sure that you have the Business Data Connectivity (likely to be renamed) Service Application started. To verify this go to Central Administration –> Manage Service Applications.
You can tell this is SharePoint Foundation since there are only a few Service Applications (SA). Ok, admittedly it could be server with very few installed, but you get the point. If you click the Manage button, you can manage any application definitions you have created already. Although, we’ll skip this since we’ll be using SharePoint Designer. If the SA is not started for some reason, go to Central Administration –> Services on Server and click Start next to the appropriate service. Also remember if you are using Windows Server 2008 R2, you will need to have the WCF hotfix installed before any SA works.
Now let’s take a look at our table. In my case I have a table of products with a few columns. I want to expose this table to SharePoint and make it editable.
Now open SharePoint Designer 2010 and connect to your SharePoint site. My server is called sp2010, so I would click open site and then enter http://sp2010. SharePoint Designer is redesigned and has a new item on the left-hand tab called External Content Types. This is where we want to go. Click the External Content Type button in the New section of the ribbon.
It will take a minute, but then you will get some details about your new External Content Type. Here is what mine looks like after I gave it a name of Products.
We’re then going to click the link Click here to discover external data sources and define operations. This is where we pick that we want to pull data from my database table. We can also use this to connect to a web service or talk to a custom .NET object.
I’m just going to go with the defaults on the next screen for my data connection. I gave it my database name of bcs_test as well as my SQL Server name. You can also configure out which identity is used here to talk to the database. Remember that you may need to grant permissions on the SQL Server itself for the appropriate user. It will then iterate your data source and display it to you. Pick out the table you want, and then right click on it. This gives you a list of operations you can add as you can see below.
As you can see, you can add individual operations such as Read Item, Read List, Create, Update, and Delete. You can also create an association if you have multiple tables related to each other. However, I want everything, so I am going to choose Create All Operations. This starts a wizard. The most important part for you will be the Parameters configuration. Here you set what field to show in a picker control as well as what the id is. Usually, you don’t need to configure much. Here I am setting that the name field should show up in the picker.
It automatically detects my primary key and maps it to the identifier for me.
You can also specify an Office Property to allow you to map things into existing types such as an Outlook Contact or Task. This lets you use Office to edit things directly in the BCS. I won’t cover that today though since that is a little bit more involved. The next step in the wizard allows you to do some filtering. In my case, I am skipping it.
When that is finished, go back to the main tab for your External Content Type and you should see something like this. It has the operations you have chosen as well as what fields are in the type.
Now, we want to save out External Content Type, by pressing the Save (Disk Icon) in the top left corner. On to the fun part. Let’s use SharePoint Designer to create an External List by using the Create Lists & Form button in the ribbon.
Clicking it you will get the following screen asking about your list. I’m calling my lists Products and I just use default values for the rest. If you are using server, you can click the Create InfoPath Form checkbox and you will be able to customize the InfoPath form for the list right there. Since we are using Foundation today, I’ll leave that unchecked.
You can also create the list directly through SharePoint as well. Once the list is created, go to your SharePoint site, navigate to the list, and you should see something that looks like this.
Comparing it to my table from the SQL Server, you can see that it matches. You can see that it looks a lot like a regular list in SharePoint. Now, what if I want to change the price on the Plush Bear? Not a problem. Click on the item and select edit, change the value in the form and save it.
Now what does the data in SQL look like?
It has the new price of course. You can also add and delete rows and perform bulk operations, but screenshots really don’t do it justice. It’s this simple to set up, you should go out and try it for yourself. One reminder, I will give you is that even though this looks like a list, it doesn’t always quite act like a list. You won’t find it in SPWeb.Lists for example. There are a also a number of other things that do and don’t work. Be on the lookout for a follow-up post on what you can and can’t do with an external list. This is a great new feature in SharePoint 2010 and I hope you will like it as much as I do.