pnp / powershell

PnP PowerShell
https://pnp.github.io/powershell
MIT License
669 stars 344 forks source link

[BUG] Set-PnPPageTextPart and Set-PnPPageWebPart cmdlets are appending extra banner section along with existing banner in the updated page after updating the new text in the Text OOB component as well as in other Components #4313

Open kssai94 opened 1 week ago

kssai94 commented 1 week ago

Reporting an Issue

While setting new text value to the Text Out of the box webpart(using Set-PnPPageTextPart cmdlet) and also while updating the webpart properties back to other oob/custom webpart (using Set-PnPPageWebPart cmdlet) programmatically through powershell, Additional banner is getting appended along with the existing banner in the updated page.

Expected behavior

Set-PnPPageTextPart and Set-PnPPageWebPart cmdlets should set the new data only on the text out of the box webpart and custom/oob webpart respectively. It should not append any new banner in the updated page after setting the text/webpart properties.

Actual behavior

Set-PnPPageTextPart and Set-PnPPageWebPart cmdlets are appending new banner after setting the new text or webpart properties for text oob/custom webparts which is weird and strange. Ideally It should not have duplicate banner in the updated page after setting new text content in webpart. It should update only the new text content in the oob/custom webpart.

Steps to reproduce behavior

Note: Please create a new Modern Page and add text OOB component and add some content in it and publish the page.

Then utilize the same page name below. Please use other parameters like credentials if you are unable to connect to Sharepoint Online.

Code Snippet

$siteUrl = "" $appId = "" $appSecret = ""

Connect to SharePoint Online $global:pnpConnection = Connect-PnPOnline -Url "$($siteUrl)" -ClientId $appId -ClientSecret $appSecret -WarningAction Ignore ReturnConnection

$pageName = "<Any new page where a simple Text OOB webpart is added in a new section after the default banner section , Eg : Page-Text-Webpart.aspx>"

try {

#Main Function
$page = Get-PnPPage -Identity "$($pageName)" -Connection $global:pnpConnection

foreach ($control in $page.Controls) {

    try {

        #region Set Webpart Properties according to the language    

        $updatedText = "Iam fine"
        #$updatedText = "How are you?"
        #$updatedText = "Hope your family is well"
        # ConvertTo-Html -InputObject $control | Out-Null
        # Write-Host $($control.ControlType)
        if($control.Type.ToString().IndexOf("PageText") -ge 0){
            $control.ToHtml($control.ControlType) | Out-Null
            Set-PnPPageTextPart -Page $pageName -InstanceId $control.InstanceId -Text $updatedText -Connection $global:pnpConnection
        }
        elseif ($control.WebPartId -eq "<AnyGuid>"){
            $control.ToHtml($control.ControlType) | Out-Null
            Set-PnPPageWebPart -Page $pageName -Identity $control.InstanceId -PropertiesJson $control.JsonWebPartData -Connection $global:pnpConnection
        }

    }
    catch {
        Write-Host $_
        $pageConversionLogCount.Status = "Error"
    }
}

} catch { Write-Host "[ERROR]: $ at $($.InvocationInfo.ScriptLineNumber) LineNumber In Main Function (Triggering Point)"

log -content "[ERROR]: $ at $($.InvocationInfo.ScriptLineNumber) LineNumber In Main Function (Triggering Point)" -path $logParentFilePath

$parentLogCount.Status = "Error"

}

$global:pnpConnection = $null

Page before updating new text in Text OOB webpart :

image

Page after updating new text in Text OOB webpart :

image

What is the version of the Cmdlet module you are running?

ModuleType Version Pre-release Name PSEdition

Manifest 2.1.1 PnP.PowerShell Desk

Which operating system/environment are you running PnP PowerShell on?

Powershell Version - 7.4.5

node version - v16.17.1

npm version - 8.15.0

Please suggest a resolution for this issue.

Note : I'm able to reproduce the same issue by using latest PnP Version - 2.12.0, Kindly check and update.

Thank you, Sreekrishna Sai

jethva-aakash commented 1 week ago

I am facing the same issue. For me, it happens when the Page has a Vertical Section. If I remove this Vertical section, it does not add the duplicate Page Title.

kssai94 commented 1 week ago

Hi Aakash,

Thanks for the acknowledgement, But i'm still able to reproduce this issue after trying to update the webpart in new page or existing page.

Now : 23/09/2024 - 4.48PM IST

Thank you, Sreekrishna Sai

kssai94 commented 1 week ago

I am facing the same issue. For me, it happens when the Page has a Vertical Section. If I remove this Vertical section, it does not add the duplicate Page Title.

Hi Aakash, Could you please check once again as issue is again reproducing, Thanks

cibun commented 1 week ago

new version of the PowerShell 2.12.0 has fixed the issue.

jethva-aakash commented 6 days ago

We already tried V2.12.0 earlier but still the same. Following are some screenshots of the same,

01-NewPage

02-Update Text

03-Duplicate Header

gautamdsheth commented 4 days ago

Hello, can you please try again with latest nightly builds and let us know ? Looks like it has been fixed .

jethva-aakash commented 4 days ago

I tried with 2.12.19-nightly but still the same.

tyagia10 commented 3 days ago

I tried even with 2.12.20-nightly but still facing the issue.