Pre-populating the BDC item picker in an application page

Adam Toth wrote a very good article on his old blog about using the BDC Entity Picker in an application page. Click here for the article.

What Adam didn’t cover however is what happens if you want to pre-load that picker with some information. In my instance, I was copying a list item with BDC data in it and wanted to allow the user to view and change the selected BDC field.

It turns out that it wasn’t as difficult as I was expecting, and after some research in the SDK about the BDC Item picker I was able to produce the effect I wanted.

I’m going to assume that you’ve followed Adam’s guide thus far and have been able to get the BDC Itempicker on your page and have it talking properly to the BDC (E.g. you can search for an item and have it populate the picker.) If you haven’t got this far, go and do that first as it’s fundamental to what we’re going to do.

So in my scenario, The list item has a BDC field for Client name. The first thing that you need to understand is how SharePoint stores the BDC Field data in the SharePoint list. I was expecting to have a new field type to play around with, but No, it’s much easier than that, you get two strings. One for the display value and one for the Entity key.

In my BDC application definition, I have an entity called dbo.Customers and this has already been added to the list definition as a Business Data column. If you write a quick console application to browse through the field names, you’ll find 2 fields, one called “Client” frm the field definition in the list and one called “dbo_x002e_Customer_ID” (This latter one was added when the field was configured.)

So with the values of these two fields we can create a PickerEntity which can be understood by the BDC Itempicker.

The PickerEntity was declared earlier in the code and then is used as follows:-

if (item["Client"] != null)
{
    if (item["dbo_x002e_Customer_ID"] != null)
    {
        peClient = new PickerEntity();
        peClient.DisplayText = item["Client"].ToString();
        peClient.Key = item["dbo_x002e_Customer_ID"].ToString();
        bdcClientSelector.Entities.Add(bdcClientSelector.ValidateEntity(peClient));
    }
}

Hopefully this will help demystify the Itempicker a little..

Paul.

Leave a Reply

Your email address will not be published.

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.