Question

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.

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top