How to rich text column properties update using pnp js

Lakshmi Lahari Tumpala 0 Reputation points
2023-05-18T07:13:02.8233333+00:00

Hi Team,

I want to update existing rich text field to enhanced rich text field without losing data in the column using pnp js

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,551 Reputation points Microsoft External Staff
    2023-05-19T02:17:52.0833333+00:00

    Hi @Lakshmi Lahari Tumpala

    Per my research, there is no such function to update a column's properties. You can refer to the functions available in pnp/js. As a workaround, I wil recommend you to use powershell to reach your requirement. Please refer to the following script

    #Load SharePoint CSOM Assemblies
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
     
    #Function to Set Multiple Lines of Text Rich Text Field Type to "Enhanced Rich Text"
    Function Set-SPOMultilineRichTextToEnhanced([String]$SiteURL, [String]$ListName, [String]$FieldInternalName)
    {
        Try {
            #Get credentials to connect
            $Cred= Get-Credential
            $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
      
            #Setup the context
            $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
            $Ctx.Credentials = $Credentials
         
            #Get the list & Fields
            $List = $Ctx.Web.lists.GetByTitle($ListName)
            $Ctx.Load($List)
            $ListFields = $List.Fields
            $Ctx.Load($ListFields)
            $Ctx.ExecuteQuery()
     
            #Get the Field to Update
            $FieldToUpdate = $ListFields | Where {$_.InternalName -eq $FieldInternalName}
             
            If($FieldToUpdate -ne $NULL)
            {
                If($FieldToUpdate.RichText -eq $True)
                {
                    #Enable Enhanced Rich Text
                    $FieldToUpdate.SchemaXml = $FieldToUpdate.SchemaXml.Replace("RichTextMode=`"Compatible`"","RichTextMode=`"FullHtml`"")
                    $FieldToUpdate.Update()
                    $Ctx.ExecuteQuery()
     
                    write-host -f Green "Field '$($FieldToUpdate.Title)' Updated in List '$($List.Title)' Successfully!" $_.Exception.Message
                }
                else
                {
                    write-host -f Yellow "Field '$($FieldToUpdate.Title)' Should be a Rich Text Field in order to Make it Enhanced Rich Text!" $_.Exception.Message
                }
            }
            else
            {
                write-host -f Yellow "Field '$($FieldToUpdate.Title)' doesn't exist in the List!" $_.Exception.Message
            }
        }
        Catch {
            write-host -f Red "Error Updating Field Settings!" $_.Exception.Message
        }
    }
    #Config Parameters
    $SiteURL="https://Crescent.sharepoint.com"
    $ListName="Projects V1"
    $FieldInternalName="Project_x0020_Description"
     
    #Call the function
    Set-SPOMultilineRichTextToEnhanced -SiteURL $SiteURL -ListName $ListName -FieldInternalName $FieldInternalName
    
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.