Other Blogs
There are no items in this list.
 
Home > Blog > Posts > Updating BDC column in lists programmatically

 Posts

Updating BDC column in lists programmatically
BDC columns in lists function slightly different from other columns. I was unable to find any documentation on msdn regarding working with BDC columns. Here's a way that I finally managed to update column value, after many unsuccessful attempts.
 
When you add a BDC column to a list, SharePoint creates several related hidden columns in the background. Important one is named [Entity]_ID. If you're displaying information from "Product" entity for example, the list will contain "Product_ID" column that you must update. This ID column contains encoded and serialized Primary Key value of your entity. SharePoint uses this column to find a match for your entry in BDC catalog.
 
Here's example code to update "Product Code" BDC column in a list.

using Microsoft.Office.Server

.ApplicationRegistry.Infrastructure;

SPListItem item = myList.Items.Add();
item["Title"] = "Product Information";
item[
"Product_ID"] = EntityInstanceIdEncoder

.EncodeEntityInstanceId(new object[]{"4312"});


item["Product"] = "SomeProductName;
item[
"Product: Type"] = "SomeOtherValue";
item.Update();

EntityInstanceIdEncoder class provides us with ability to encode and decode the entity keys. If your BDC column is setup to also display other columns in the entity you have to manually assign value to those as well. I was unable to get the list to update related BDC columns based on the primary one.

Comments

Helpful

Thank you, that was very helpful.
System Account at 4/15/2007 10:42 AM

Updating BDC column in lists programmatically using Lists.asmx

How you ever try to use sharepoint WebServices to update BDC column?

For some reason, I couldn't set it by using the Lists.asmx

Thank you in advance!
Yuting
System Account at 12/17/2007 8:24 AM

Same Issue

I'm having the same issues with addint a bdc list item...

bummer - this would be way cool if it worked!
System Account at 1/24/2008 8:11 AM

ID Field  - Proper data type

Don't forget that if your primary key lookup is an Int32 (as mine was) that you must pass an int instead of a string.

e.g.
listItem[listFieldName] = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { Convert.ToInt32(listValue) });
System Account at 3/13/2008 12:08 PM

Great

I was looking exactly this. Your post really saved me a lot of time.
System Account at 10/2/2008 9:41 PM
All Rights Reserved, © 2008 Portal Solutions, LLC