Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

programmatically setting a BusinessDataField

  Asked By: Deepak    Date: Sep 03    Category: Sharepoint    Views: 2389

I want to set a Business Data field in a list via code. Does any one of you have an idea, how to do this?

If I access item[ID] I just get a System.String.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Omar Arnold     Answered On: Sep 03

My original post may have been of topic (I had read your post to mean add a new BDC field). However on re-reading I think you mean how to set  the data.

The post Updating BDC column in lists programmatically  goes some way to solving this.

Quote:

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.

 
Didn't find what you were looking for? Find more on programmatically setting a BusinessDataField Or get search suggestion and latest updates.