Skip to content

new sample script to update multiline text field #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions scripts/spo-multiline-field-properties/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Updating Multiline Text Field Properties in SharePoint

## Summary

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.

For example, at the **site level**, you can configure properties such as:
- **Append Changes to Text**
- **Number of Lines**
- **Field Type**: Plain Text, Rich Text, or Enhanced Rich Text

However, these settings may not appear at the **library/list level**

![Example Screenshot](assets/multilinetext_appendtoText_library_missing.png)

### Prerequisites

- The user account that runs the script must have access to the SharePoint Online site.

# [PnP PowerShell](#tab/pnpps)

```powershell
param (
[Parameter(Mandatory = $true)]
[string]$Url,

[Parameter(Mandatory = $true)]
[string]$ListName,

[Parameter(Mandatory = $true)]
[string]$FieldName,

[Parameter(Mandatory = $true)]
[ValidateSet("EnhancedRichText", "PlainText", "RichText")]
[string]$TextType = "EnhancedRichText",

[Parameter(Mandatory = $true)]
[ValidateSet("Yes", "No")]
[string]$AppendOnly = "Yes"
)

# Connect to SharePoint site
Connect-PnPOnline -Url $Url

# Map the TextType to corresponding RichTextMode and RichText values
switch ($TextType) {
"EnhancedRichText" {
$RichTextMode = "FullHtml"
$RichText = $true
}
"PlainText" {
$RichTextMode = "Compatible"
$RichText = $false
}
"RichText" {
$RichTextMode = "Compatible"
$RichText = $true
}
}

# Convert AppendOnly parameter to boolean
$AppendOnlyValue = if ($AppendOnly -eq "Yes") { $true } else { $false }

# Update field properties
Set-PnPField -List $ListName -Identity $FieldName -Values @{
AppendOnly = $AppendOnlyValue
RichTextMode = $RichTextMode
RichText = $RichText
NumLines = "6"
UnlimitedLengthInDocumentLibrary = $false
} -ErrorAction Stop

# Handle properties that cannot be updated directly
$Field = Get-PnPField -List $ListName -Identity $FieldName -ErrorAction Stop
$FieldSchemaXml = [xml]$Field.SchemaXml

if ($TextType -eq "EnhancedRichText" -or $TextType -eq "RichText") {
$FieldSchemaXml.Field.SetAttribute("RichTextMode", $RichTextMode)
$FieldSchemaXml.Field.SetAttribute("NumLines", "8")
}

Set-PnPField -List $ListName -Identity $FieldName -Values @{
SchemaXml = $FieldSchemaXml.OuterXml
} -ErrorAction Stop
```

[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]

***

## Source Credit

Sample first appeared on [Updating Multiline Text Field Properties in SharePoint Using PowerShell](https://reshmeeauckloo.com/posts/powershell-sharepoint-multilinefield-appendtext/)

## Contributors

| Author(s) |
|-----------|
| [Reshmee Auckloo](https://github.com/reshmee011) |


[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-multiline-field-properties" aria-hidden="true" />
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions scripts/spo-multiline-field-properties/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[
{
"name": "spo-multiline-field-properties",
"source": "pnp",
"title": "Updating Multiline Text Field Properties in SharePoint",
"shortDescription": "Updating Multiline Text Field Properties in SharePoint",
"url": "https://pnp.github.io/script-samples/spo-multiline-field-properties/README.html",
"longDescription": [
"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."
],
"creationDateTime": "2025-05-07",
"updateDateTime": "2025-05-07",
"products": [
"SharePoint",
"Libraries"
],
"metadata": [
{
"key": "PNP-POWERSHELL",
"value": "3.0"
}
],
"categories": [
"SharePoint"
],
"tags": [
"modern",
"Connect-PnPOnline",
"Get-PnPField",
"Set-PnPField"
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-multiline-field-properties/assets/preview.png",
"alt": ""
}
],
"authors": [
{
"gitHubAccount": "reshmee011",
"company": "",
"pictureUrl": "https://avatars.githubusercontent.com/u/7693852?v=4",
"name": "Reshmee Auckloo"
}
],
"references": [
{
"name": "Want to learn more about PnP PowerShell and the cmdlets",
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
"url": "https://aka.ms/pnp/powershell"
}
]
}
]