0

I have used following power-shell script for creating a new content type with one custom column.

$siteURL = "My Site URL"
$contentTypeName = "Test Content Type 1"
$contentTypeGroupName = "Content Type Group Name"

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Reflection.Assembly]::LoadWithPartialName("System.Collections.Specialized")
$site = New-Object microsoft.sharepoint.spsite($siteURL)
$web = $site.openweb()

$cTypeID = $web.AvailableContentTypes["Item"]
$cTypes = $web.ContentTypes
$cType = New-Object Microsoft.SharePoint.SPContentType($cTypeID, $cTypes, $contentTypeName)
$cType.Group = $contentTypeGroupName
$cTypes.Add($cType)

$web.fields.add("myField2", ([Type]"Microsoft.SharePoint.SPFieldType")::Text, $false)
$field = $web.fields.getfield("myField2")
$fieldLink = new-object Microsoft.SharePoint.SPFieldLink($field)
$cType.fieldlinks.add($fieldLink)
$cType.Update() 

$web.Dispose()
$site.Dispose()

This code creates the content type successfully and adds a site column to it.

But when i go to content type gallery and try to expand the content type. Only one field i.e. "myField2" is appearing in the list of columns. I was expecting "Title" field to also appear in the list, as its implicitly part of every custom content type. But its not there.

Can anybody explain why is it so ? or My understanding is wrong somewhere ?

Thanks in advance.

2
  • After executing few power-shell scripts i found that the "Title" column is not part of the "MyContentType.Fields" collection, but it is part of "MyContentType.FieldLinks". So, it is not getting displayed in the list of columns for "MyContentType". On my environment i can see a custom content type where "Title" column is listed in the list of columns for that content type.
    – Amit Tyagi
    Commented Oct 6, 2014 at 22:38
  • One more update, in my environment I can't see the title column even for "Item" content type.
    – Amit Tyagi
    Commented Oct 6, 2014 at 23:35

1 Answer 1

0

So, it turned out that somebody screwed up with the default Item content type and hence the Title column was not visible under the Item content type. And, hence also not visible under my custom content type, as it was inheriting from Item content type.

While googling around, i came across a similar question here. Jason provided the STSADM commands for resetting the built-in fields to their default state. Below are the commands which did the trick,

stsadm -o deactivatefeature -name Fields -url http://Site Collection URL -force
stsadm -o activatefeature -name Fields -url http://Site Collection URL -force

What these commands are doing is, they are actually deactivating and activating back the Fields feature on the affected Site Collection.

1
  • If this answer solved your problem, please mark it as Accepted, so it doesn't pop up in the Unanswered questions section anymore.
    – jcp
    Commented Jan 5, 2016 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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