Skip to content
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

[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
1 task
kssai94 opened this issue Sep 19, 2024 · 13 comments
Labels
bug Something isn't working

Comments

@kssai94
Copy link

kssai94 commented Sep 19, 2024

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?

  • Windows

##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

@kssai94 kssai94 added the bug Something isn't working label Sep 19, 2024
@jethva-aakash
Copy link

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
Copy link
Author

kssai94 commented Sep 23, 2024

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
Copy link
Author

kssai94 commented Sep 23, 2024

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

@kssai94 kssai94 changed the title [BUG] Set-PnPPageTextPart and Set-PnPPageWebParts 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 [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 Sep 23, 2024
@cibun
Copy link

cibun commented Sep 24, 2024

new version of the PowerShell
2.12.0 has fixed the issue.

@jethva-aakash
Copy link

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
Copy link
Collaborator

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

@jethva-aakash
Copy link

I tried with 2.12.19-nightly but still the same.

@tyagia10
Copy link

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

@jethva-aakash
Copy link

@gautamdsheth It seems to me like the issue is connected with the recent changes by Microsoft related to Page content handling. Could it be that the CSOM library does not support the latest M365 version yet? Is there any solution or workaround that you can suggest?

@tarjeieo
Copy link

I'm seeing this issue with pages with vertical sections when I just update/publish them, without adding or modifying the page itself. The page will have it's banner-section "reset" and an extra banner web part is added.

Repro with 2.12.0:

$CurrentItem = Get-PnPListItem -List SitePages -Id 69
Set-PnPListItem -List SitePages -Identity $CurrentItem.Id -Values @{"Modified" = $NowValue} -UpdateType UpdateOverwriteVersion
Set-PnPPage -Identity $CurrentItem.FieldValues.FileLeafRef -Publish

This is how it looks after:
image

@SteenMolberg
Copy link

I ran into this when creating automatic updating of page with a script based of PNP Powershell. I don't think the bug is in PNP Powershell, but when working with the page, like replacing a webpart, an additional header is inserted into "LayoutWebpartsContent" field. It looks like it is related to a vertical section on the page.

You can reset the "LayoutWebpartsContent" with the following script:

Set-PnPListItem -List "Site Pages" -Identity [insert here id of page item] -Values @{ LayoutWebpartsContent = "<div></div>" } -UpdateType SystemUpdate

@armourking
Copy link

You can reset the "LayoutWebpartsContent" with the following script:

Set-PnPListItem -List "Site Pages" -Identity [insert here id of page item] -Values @{ LayoutWebpartsContent = "<div></div>" } -UpdateType SystemUpdate

This works great, thank you!

@Galmiar57
Copy link

Galmiar57 commented Dec 6, 2024

Duplicate banner issue on pages with a vertical section (with PnP 2.12.0)

Bug Description

This issue occurs when creating a page with a banner (full-width section) and a vertical section. After saving the page using Get-PnPPage, the banner is duplicated. Subsequent attempts to fix the issue temporarily (e.g., using Set-PnPListItem) result in a loss of the full-width format for the banner, and the issue reoccurs after each update.

Steps to Reproduce

  1. Create a page with the following structure:
    • A banner in a full-width section.
    • A vertical section.
  2. Save any update on this page using the Get-PnPPage command.
  3. Navigate to the page in a browser and observe that the banner is duplicated.
  4. Apply the workaround:
    • Use the command Set-PnPListItem -Identity <PageId> -Values @{"LayoutWebpartsContent"="<div></div>"}.
  5. Navigate to the page again:
    • The duplicate banner is resolved, but the full-width format for the banner is lost.
  6. Save the page again using Get-PnPPage.
  7. Navigate to the page and observe that the duplicate banner issue reoccurs.

Expected Behavior

  • The page should maintain the full-width section layout for the banner.
  • The banner should not be duplicated after saving or updating the page.

Actual Behavior

  • The banner is duplicated after the first save using Get-PnPPage.
  • Applying the workaround removes the duplicate banner but breaks the full-width layout.
  • The issue reoccurs after each save or update.

Screenshots

Step 1 : Create a page
step1

Step 2 : Save the page using the Get-PnPPage command.
step2

Step 3 : Navigate to the page in a browser and observe that the banner is duplicated.
step3

Step 4 : Apply the workaround Set-PnPListItem -Identity <PageId> -Values @{"LayoutWebpartsContent"="<div></div>"}
step4

Step 5 : The duplicate banner is resolved, but the full-width format for the banner is lost
step5

Step 6 : Save the page again using Get-PnPPage
step6

Step 7 : Navigate to the page and observe that the duplicate banner issue reoccurs.
step7

Additional Context

This issue makes it difficult to maintain the desired layout when pages include both a full-width section and a vertical section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants