|
| 1 | +# Updating Multiline Text Field Properties in SharePoint |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +Managing multiline text fields in SharePoint can be tricky, especially when certain field properties are not visible or editable at the library/list level, even though they are available at the site level. |
| 6 | + |
| 7 | +For example, at the **site level**, you can configure properties such as: |
| 8 | +- **Append Changes to Text** |
| 9 | +- **Number of Lines** |
| 10 | +- **Field Type**: Plain Text, Rich Text, or Enhanced Rich Text |
| 11 | + |
| 12 | +However, these settings may not appear at the **library/list level** |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +### Prerequisites |
| 17 | + |
| 18 | +- The user account that runs the script must have access to the SharePoint Online site. |
| 19 | + |
| 20 | +# [PnP PowerShell](#tab/pnpps) |
| 21 | + |
| 22 | +```powershell |
| 23 | +param ( |
| 24 | + [Parameter(Mandatory = $true)] |
| 25 | + [string]$Url, |
| 26 | +
|
| 27 | + [Parameter(Mandatory = $true)] |
| 28 | + [string]$ListName, |
| 29 | +
|
| 30 | + [Parameter(Mandatory = $true)] |
| 31 | + [string]$FieldName, |
| 32 | +
|
| 33 | + [Parameter(Mandatory = $true)] |
| 34 | + [ValidateSet("EnhancedRichText", "PlainText", "RichText")] |
| 35 | + [string]$TextType = "EnhancedRichText", |
| 36 | +
|
| 37 | + [Parameter(Mandatory = $true)] |
| 38 | + [ValidateSet("Yes", "No")] |
| 39 | + [string]$AppendOnly = "Yes" |
| 40 | +) |
| 41 | +
|
| 42 | +# Connect to SharePoint site |
| 43 | +Connect-PnPOnline -Url $Url |
| 44 | +
|
| 45 | +# Map the TextType to corresponding RichTextMode and RichText values |
| 46 | +switch ($TextType) { |
| 47 | + "EnhancedRichText" { |
| 48 | + $RichTextMode = "FullHtml" |
| 49 | + $RichText = $true |
| 50 | + } |
| 51 | + "PlainText" { |
| 52 | + $RichTextMode = "Compatible" |
| 53 | + $RichText = $false |
| 54 | + } |
| 55 | + "RichText" { |
| 56 | + $RichTextMode = "Compatible" |
| 57 | + $RichText = $true |
| 58 | + } |
| 59 | +} |
| 60 | +
|
| 61 | +# Convert AppendOnly parameter to boolean |
| 62 | +$AppendOnlyValue = if ($AppendOnly -eq "Yes") { $true } else { $false } |
| 63 | +
|
| 64 | +# Update field properties |
| 65 | +Set-PnPField -List $ListName -Identity $FieldName -Values @{ |
| 66 | + AppendOnly = $AppendOnlyValue |
| 67 | + RichTextMode = $RichTextMode |
| 68 | + RichText = $RichText |
| 69 | + NumLines = "6" |
| 70 | + UnlimitedLengthInDocumentLibrary = $false |
| 71 | +} -ErrorAction Stop |
| 72 | +
|
| 73 | +# Handle properties that cannot be updated directly |
| 74 | +$Field = Get-PnPField -List $ListName -Identity $FieldName -ErrorAction Stop |
| 75 | +$FieldSchemaXml = [xml]$Field.SchemaXml |
| 76 | +
|
| 77 | +if ($TextType -eq "EnhancedRichText" -or $TextType -eq "RichText") { |
| 78 | + $FieldSchemaXml.Field.SetAttribute("RichTextMode", $RichTextMode) |
| 79 | + $FieldSchemaXml.Field.SetAttribute("NumLines", "8") |
| 80 | +} |
| 81 | +
|
| 82 | +Set-PnPField -List $ListName -Identity $FieldName -Values @{ |
| 83 | + SchemaXml = $FieldSchemaXml.OuterXml |
| 84 | +} -ErrorAction Stop |
| 85 | +``` |
| 86 | + |
| 87 | +[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] |
| 88 | + |
| 89 | +*** |
| 90 | + |
| 91 | +## Source Credit |
| 92 | + |
| 93 | +Sample first appeared on [Updating Multiline Text Field Properties in SharePoint Using PowerShell](https://reshmeeauckloo.com/posts/powershell-sharepoint-multilinefield-appendtext/) |
| 94 | + |
| 95 | +## Contributors |
| 96 | + |
| 97 | +| Author(s) | |
| 98 | +|-----------| |
| 99 | +| [Reshmee Auckloo](https://github.com/reshmee011) | |
| 100 | + |
| 101 | + |
| 102 | +[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] |
| 103 | +<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-multiline-field-properties" aria-hidden="true" /> |
0 commit comments