Implement multiline options support and legacy field handling in Dynamic Poll
This commit is contained in:
@@ -34,7 +34,39 @@ try {
|
||||
}
|
||||
|
||||
Ensure-Field -List $polls -InternalName 'Question' -SchemaXml '<Field Type="Text" DisplayName="Question" Name="Question" StaticName="Question" Required="TRUE" />'
|
||||
Ensure-Field -List $polls -InternalName 'Options' -SchemaXml '<Field Type="MultiChoice" DisplayName="Options" Name="Options" StaticName="Options" Required="TRUE" FillInChoice="TRUE"><CHOICES><CHOICE>Option 1</CHOICE><CHOICE>Option 2</CHOICE></CHOICES></Field>'
|
||||
|
||||
$legacyOptionsField = $null
|
||||
try { $legacyOptionsField = $polls.Fields.GetFieldByInternalName('Options') } catch { }
|
||||
if ($legacyOptionsField) {
|
||||
$legacyOptionsField.Title = 'Options (legacy)'
|
||||
$legacyOptionsField.Required = $false
|
||||
$legacyOptionsField.ShowInNewForm = $false
|
||||
$legacyOptionsField.ShowInEditForm = $false
|
||||
$legacyOptionsField.ShowInDisplayForm = $false
|
||||
$legacyOptionsField.Update()
|
||||
}
|
||||
|
||||
Ensure-Field -List $polls -InternalName 'OptionsText' -SchemaXml '<Field Type="Note" DisplayName="Options" Name="OptionsText" StaticName="OptionsText" Required="FALSE" NumLines="8" RichText="FALSE" AppendOnly="FALSE" />'
|
||||
|
||||
if ($legacyOptionsField) {
|
||||
foreach ($item in $polls.Items) {
|
||||
if (-not [string]::IsNullOrWhiteSpace([string]$item['OptionsText']) -or $null -eq $item[$legacyOptionsField.Id]) { continue }
|
||||
$legacyValue = $legacyOptionsField.GetFieldValue([string]$item[$legacyOptionsField.Id])
|
||||
$optionLines = New-Object System.Collections.Generic.List[string]
|
||||
if ($legacyValue -is [Microsoft.SharePoint.SPFieldMultiChoiceValue]) {
|
||||
for ($choiceIndex = 0; $choiceIndex -lt $legacyValue.Count; $choiceIndex++) {
|
||||
if (-not [string]::IsNullOrWhiteSpace($legacyValue[$choiceIndex])) { $optionLines.Add($legacyValue[$choiceIndex]) }
|
||||
}
|
||||
}
|
||||
elseif (-not [string]::IsNullOrWhiteSpace([string]$legacyValue)) {
|
||||
$optionLines.Add([string]$legacyValue)
|
||||
}
|
||||
if ($optionLines.Count -gt 0) {
|
||||
$item['OptionsText'] = ($optionLines -join [Environment]::NewLine)
|
||||
$item.SystemUpdate($false)
|
||||
}
|
||||
}
|
||||
}
|
||||
Ensure-Field -List $polls -InternalName 'StartDate' -SchemaXml '<Field Type="DateTime" DisplayName="Start date" Name="StartDate" StaticName="StartDate" Format="DateTime" />'
|
||||
Ensure-Field -List $polls -InternalName 'EndDate' -SchemaXml '<Field Type="DateTime" DisplayName="End date" Name="EndDate" StaticName="EndDate" Format="DateTime" />'
|
||||
Ensure-Field -List $polls -InternalName 'IsActive' -SchemaXml '<Field Type="Boolean" DisplayName="Active" Name="IsActive" StaticName="IsActive"><Default>0</Default></Field>'
|
||||
@@ -58,4 +90,3 @@ try {
|
||||
finally {
|
||||
if ($web) { $web.Dispose() }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user