Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Help adding a BDC Column to a list programatically

  Asked By: Loren    Date: Jul 04    Category: Sharepoint    Views: 1474

I am trying to add a BDC column to a sharepont list in code. The app that I am working on has 140 lists that I would rather not configure by hand...

I am getting close but can't seem to find the missing step.

First I connect the SSP to the SqlSessionProvider:

SqlSessionProvider.Instance().SetSharedResourceProviderToUse("My SSP")

I get the list that I am adding to and call:
list.Fields.AddFieldAsXml( ... )
list.Update()

The ... is the XmlSchema that I have extracted from another manually created BDC column.
I have replaced the ID with a new guid and the SourceId with the ID from the list.

This almost works. The BDC fields are added to the list (including the hidden entityXXX_ID column ). However they don't work.
When I view the column of the new business column I get the error "Exception thrown while initializing the BusinessDataFieldEditor"

Can anyone give me a hint of what I am doing wrong.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Aditiya Kapale     Answered On: Jul 04

I have fixed this myself.

Here is the solution in Boo (you will need to extract the field defintion yourself from a working  example):


import System
import Microsoft.SharePoint
import Microsoft.SharePoint.Portal
import Microsoft.SharePoint.Portal.WebControls
import Microsoft.Office.Server
import Microsoft.Office.Server.ApplicationRegistry.Infrastructure

SqlSessionProvider.Instance().SetSharedResourceProviderToUse("My SSP Name")

site = SPSite("http://mysharepointsite:12345")
web = site.OpenWeb()
list = web.Lists["My list  Name"]

fieldContent = .... field defintion with id replaced with new guid and sourceId replaced by list.Id

fieldName = list.Fields.AddFieldAsXml(fieldContent)
list.Update()

busfield as BusinessDataField = list.Fields[fieldName]
busfield.SystemInstanceName = "My system instance"
busfield.EntityName = "scope.Entity"
busfield.BdcFieldName = "MyFieldName"
busfield.Profile = .... (copy from source field)
busfield.HasActions = true

busfield.Update()

 
Didn't find what you were looking for? Find more on Help adding a BDC Column to a list programatically Or get search suggestion and latest updates.




Tagged: