$docSite = new-object Microsoft.SharePoint.SPSite($siteURL)
$docWeb = $docSite.OpenWeb()
$lncustomListName listName
$CustomfieldName = "MyChoiceColumn"
/* To create choice field */
Add-SPMultiChoiceField -listName $lncustomListName
/* Method to create choice field */
function Add-SPMultiChoiceField([string]$listName)
{
$OpenList = $docWeb.Lists[$listName]
$multiChoiceCol = "<Field Name='"+ $CustomfieldName +"' Type='MultiChoice' FillInChoice='FALSE' DisplayName='"+ $CustomfieldName +"'><Default>MyChoice1</Default><CHOICES><CHOICE>MyChoice2</CHOICE><CHOICE>ERM</CHOICE><CHOICE>MyChoice3</CHOICE></CHOICES></Field>"
$OpenList.Fields.AddFieldAsXml($multiChoiceCol,$true,
[Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)
}
$docWeb = $docSite.OpenWeb()
$lncustomListName listName
$CustomfieldName = "MyChoiceColumn"
/* To create choice field */
Add-SPMultiChoiceField -listName $lncustomListName
/* Method to create choice field */
function Add-SPMultiChoiceField([string]$listName)
{
$OpenList = $docWeb.Lists[$listName]
$multiChoiceCol = "<Field Name='"+ $CustomfieldName +"' Type='MultiChoice' FillInChoice='FALSE' DisplayName='"+ $CustomfieldName +"'><Default>MyChoice1</Default><CHOICES><CHOICE>MyChoice2</CHOICE><CHOICE>ERM</CHOICE><CHOICE>MyChoice3</CHOICE></CHOICES></Field>"
$OpenList.Fields.AddFieldAsXml($multiChoiceCol,$true,
[Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)
}
No comments:
Post a Comment