0

I need to add new choice field to existed content type. I'd like to do it in feature activate segment. I understand, I need to get content type by ID or name, then create new choice field with my options, default value and choice type and at last add field to content type. I googled whole day but I don't understand how to realize it.

Show me please by example how to resolve my task.

0

Create the site column as a separate action from the content type, and then use a "FieldLinkCreationInformation" object to add the site column to the content type. See this page on msdn for a code sample, or google "FieldlinkCreationInformation" for more examples. Or, following is an incomplete PowerShell snippet with the important bits:

#load the existing site columns
$context.Load($web.Fields)
$context.ExecuteQuery()

#get a reference to the site column that needs to be added to a content type
$mySiteColumn= $web.Fields.GetByTitle($siteColumnName)
$context.Load($mySiteColumn)
$context.ExecuteQuery()

#Get the FieldLink, and add it to the content type 
$mySiteColumnLinkInfo = new-object Microsoft.SharePoint.Client.FieldLinkCreationInformation
$mySiteColumnLinkInfo.Field=$mySiteColumn
$varthrowaway = $myContentType.FieldLinks.Add($mySiteColumnLinkInfo)

$myContentType.Update($true)
$context.ExecuteQuery()
  • CSOM is not in my case. And didn't prefer use Powershell for such actions: I think all updates should be centralized store in wsp package for repeated use. – Ivan Tikhonov Jul 19 '17 at 20:38
  • WSP is on the way out. But if you want server-side, it's a similar procedure, in that the site column is created separately from the content type, and then added via fieldlinks. An example is here: c-sharpcorner.com/UploadFile/40e97e/… – Mike2500 Jul 19 '17 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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