Setting the value of a BDC field Programmatically
You cannot set the value of a BDC (Business Data Catalog) field in the same way that you set standard fields in SharePoint e.g:
SPListItem item = myList.Items.Add(); item["Title"] = "Product Information";
Instead you must use the EncodeEntityInstanceId method of the EntityInstanceIdEncoder class of the Microsoft.Office.Server.ApplicationRegistry.Infrastructure class library. First you can detect if your field is a BDC field by:
if(item.Fields["MyField"].TypeAsString == "BusinessData")
You then need to:
//Get a reference to the field SPField myField = spItem.Fields["EmployeeID]; //Get the entity Name for the field XmlDocument xmlData = new XmlDocument(); xmlData.LoadXml(myField.SchemaXml); String entityName = xmlData.FirstChild.Attributes["RelatedFieldWssStaticName"].Value; //Set the Entity Instance value spItem[entityName] = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { "123456" }); //Set the field display value spItem["EmployeeID"] = "123456;
Connected WebParts – No Filtered Parameters
Posted by Dominick Cosgrove at 9:05 PM Labels: Development, SharePoint
OK this may be obvious but it caught me out and god knows it caused me to tear my hair out for a while.
I was creating a custom consumer WebPart that I wanted to connect to a URL and BDC Filter WebParts. There are loads of examples out there of how to do this. Basically Windows SharePoint Services makes use of the connection framework and provides additional interfaces called IFilterValues and IItransformableFilterValues to make it easy to create Web Part connections for filtering scenarios.
The issue I had was once I implement the code as per the various examples on the web, there were no filter parameters available to when you configure the connection.
The problem lies with the ConsumerParameterCapabilities Enumeration, which is used by a consumer Web part to indicate supported filter parameter capabilities. The samples on the web all seem to use:
ConsumerParameterCapabilities.SupportsMultipleValues
and
ConsumerParameterCapabilities.SupportsAllValue
Unfortunately this did not seem sufficient for the BDC and URL filter WebParts, after some trail and error I established that the minimum required is:
ConsumerParameterCapabilities.SupportsAllValue
or
ConsumerParameterCapabilities.SupportsEmptyValue
How ever it does work if you specify all ConsumerParameterCapabilites. The ConsumerParameter method allows you to have or statements so you can effectively set the parameters like this:
parameters.Add(new ConsumerParameter( "Personnel Number", ConsumerParameterCapabilities.SupportsAllValue | ConsumerParameterCapabilities.SupportsEmptyValue )
or
parameters.Add(new ConsumerParameter( "Personnel Number", ConsumerParameterCapabilities.SupportsAllValue | ConsumerParameterCapabilities.SupportsEmptyValue | ConsumerParameterCapabilities.SupportsMultipleValues | ConsumerParameterCapabilities.SupportsSingleValue ) );
So to summaries, make sure you are using the correct ConsumerParameterCapabilities for your provider webpart or else you will not see the parameters you are expecting to see.
References
Writing a Simple Filter Consumer Web Part Sample
MOSS 2007 Filter webparts part 1 – create your own provider and consumer