Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have site content type called ContractBase that has a bunch of fields that are used in contracts. I created some other site content types (ContractType1 and ContractType2) that inherit from ContractBase so that I can associate diferent word templates with them.

I have a Document Library alled Contracts that has content types enabled, and it uses ContractType1 and ContractType2.

I added a BusinessData Column to the Contracts Library to lookup a ContractNumber in a sql Database.

All the above were created with the Object Model.

It works great, When I add a document of type ContractType1 or ContractType2, the External DataPicker appears and users can select a contract number from our sql database.

But when I created a new site content type ContractType3 (that also inheritted from ContractBase) and added it to the Contracts Document Library, the ContractNumber columns is not associated with that content type.

I can't remove and add back the ContractNumber because i would loos all my existing data.

How can I get the ContractNumber to appear on newly added content Types?

share|improve this question
add comment

3 Answers

I had the following problem (I think that's the same as you):

I have a document library with an external content type column. If I create the column after I associated the document content types all goes well. I can access the external data from within Word.

If I add another document content type after I've created the external data column, I can manually associate it via the web-GUI (Add list column to content type). But those columns aren't accessible in Word. Even the whole "document properties" menu under quick parts is empty after that.

So I fired up PowerShell and looked at the newly added content type and its fields. The ID Field of the external content type was not associated. That's clearly a bug.

So I wrote myself a small posh-script which copies fields from one content type to another.

That's the code (just a quick dirty fix...):

$web = Get-SPWeb "http://spdev"
$list = $web.Lists["TestLib"]

$cts = $list.ContentTypes
$source = $cts["ContractType1"]
$dest = $cts["ContractType3"]

foreach ($field in $source.Fields)
{
    if ($dest.Fields.Contains($field.Id) -ne $true)
    {
        $query = "Do you want to add " + $field.Title + "? (y/n)"
        $result = Read-Host -Prompt $query

        if ($result -eq "y")
        {
        $fieldLink = New-Object Microsoft.SharePoint.SPFieldLink($field)
            $dest.FieldLinks.Add($fieldLink);
            Write-Host("Adding " + $field.Title)
        }
    }
}
$dest.Update()
share|improve this answer
add comment

Great question!

In order to add an existing list column to a new content type, go to the list settings, and click on the content type for which you want to add a new column. It will bring up a List Content Type Information Menu, and at the bottom there is the option to 'Add from existing site or list columns'. You should be able to add the existing column to your new content type in the menu it brings up.

Let me know how it goes!

share|improve this answer
    
I vcan't add from Sote Columns because BusinessData Columns can't be site columns –  russellg Apr 20 '12 at 1:33
    
shoot you absolutely right and unfortunately I don't have a solution for you, sorry –  Zork Apr 20 '12 at 20:51
add comment
  1. Simply adding a column to a content type once the content type is already added to the library, would not add it to all content types, because the particular Content Type, after being added to the library is an Instance of the actual CT at the Web/Site level.
  2. ECT Columns are not actual Site Columns, therefore they cannot be used in creating content types as such with the hope it shall be inherited.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.