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.

1 Answer 1

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() 
2
  • 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. Commented Jul 19, 2017 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/… Commented Jul 19, 2017 at 20:46

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.