0

I have created a BDC model using Visual Studio and deployed it using a WSP to the server.

Next I want to add an External Data Column (Field) using a External Content Type in the BDC model to an existing (generic) list using powershell.

How would I do this? I don't want to do this manually for each list using the UI or SharePoint designer as I want to automate the process and have it repeatable.

1 Answer 1

0

You can create field schema for your external data column. You can follow this link for doing it.

Then use following PowerShell script to create field into list

$web = Get-SPWeb "Web Url"
$list = $web.Lists["Your List Title"]
$fields = $list.Fields
$firstNameColXml = "Your field schema here"
$noteFieldSchema = "Your note field schema"

$fieldBCS = $fields.AddFieldAsXml($firstNameColXml,$true [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView) 
$fieldBCS .update()

$fieldBCSNote = $fields.AddFieldAsXml($noteFieldSchema,$true,
[Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView) 
 $fieldBCSNote.update()

Your field schema should be as follows

For BCS Field

   <Field Type="BusinessData" 
   DisplayName="test" Required="FALSE" 
   ID="{3db01d5e-a61e-47ab-922d-a3ba3db906a8}" 
   StaticName="test" BaseRenderingType="Text"
   Name="test" SystemInstance="[External System]" 
   EntityNamespace="[Namespace]" EntityName="[Name]" 
   BdcField="[Field Name in BCS]" HasActions="True" 
   SecondaryFieldBdcNames="0" RelatedField="[Field Name in BCS]" 
   SecondaryFieldWssNames="0" RelatedFieldBDCField="" 
   RelatedFieldWssStaticName="[Field Name in BCS]"       SecondaryFieldsWssStaticNames="0" AddFieldOption="AddToAllContentTypes, AddFieldToDefaultView" />

For Note field

<Field Type="Note" DisplayName="[Field display name]" Hidden="TRUE"       ReadOnly="TRUE"BdcField="[Field Name in BCS]" ID="{9c03ea22-4a95-4902-b549-90ff7a624530}" StaticName="[Field Name in BCS]" Name="[Field Name in BCS]"/>

Hope it will help to you

5
  • What is the noteField? Is it what is seen in the views? Commented Jun 2, 2015 at 8:55
  • It is one hidden field used by sharepoint. When you create External Data from UI then that field will be automatically added by SharePoint Commented Jun 2, 2015 at 9:11
  • The ID attribute, do I set it to whatever? Commented Jun 2, 2015 at 9:19
  • Yes. you can set any random GUID. Commented Jun 2, 2015 at 9:20
  • I got the XML for the external data and notes fields by first adding the external data column using the UI and then using powershell to extract their SchemaXml. I removed all attributes not mentioned in the answer and then it worked. Commented Jun 2, 2015 at 10:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.