Navigate Up
Sign In
Home > Blog > Posts > Updating BDC column in lists programmatically
 

 Posts

 
February 19
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 on 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 on 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 on 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 on 3/13/2008 12:08 PM

Great

I was looking exactly this. Your post really saved me a lot of time.
System Account on 10/2/2008 9:41 PM

Not working correctly

Hi,

As you write you just encode the value what you write back to the list. This worked not for me. If I look within the list the field is empty and not shown at all. All actions correctly bound. If I synchronize the Listitems everything is updated correctly! I think it is necessary to bind the instance before...

Whatever.

This sample listItem[listFieldName] = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { Convert.ToInt32(listValue) });  is just wrong. My ID is a text value with a number. So if I would convert an error occurs. Remove Convert.ToInt32. This is not necessary.

Anyway. Thanks for this article. Not so many articles about coding and BDC exists. This makes me a little bit said. A lot of research is necessary.

Timo
 on 3/10/2009 11:07 AM

Not working correctly

Hi,

As you write you just encode the value what you write back to the list. This worked not for me. If I look within the list the field is empty and not shown at all. All actions correctly bound. If I synchronize the Listitems everything is updated correctly! I think it is necessary to bind the instance before...

Whatever.

This sample listItem[listFieldName] = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { Convert.ToInt32(listValue) });  is just wrong. My ID is a text value with a number. So if I would convert an error occurs. Remove Convert.ToInt32. This is not necessary.

Anyway. Thanks for this article. Not so many articles about coding and BDC exists. This makes me a little bit said. A lot of research is necessary.

Timo
 on 3/10/2009 3:12 PM

All Rights Reserved, © 2010 Portal Solutions, LLC