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] Remove sections of the page not working #666

Closed
5 tasks
Employee87 opened this issue Aug 31, 2021 · 4 comments
Closed
5 tasks

[BUG] Remove sections of the page not working #666

Employee87 opened this issue Aug 31, 2021 · 4 comments
Assignees
Labels
area: pages API 📄 Working with modern pages bug Something isn't working

Comments

@Employee87
Copy link

Reporting an Issue or Missing Feature

Issue

Expected behavior

It removes the sections of the page.

Actual behavior

Sections of the page still persists. No error thrown. I tried a test where the Home page has 2 sections. And it prints out 1 and then 0.

Steps to reproduce behavior

Connect-PnPOnline -Url "https://mysite.sharepoint.com/sites/TestSite" -Interactive
 $pg = Get-PnPPage -Identity "Home"
 $sectionsCount = $pg.Sections.Count
 for($i=$sectionsCount-1; $i -ge 0; $i--) {
     write-host $i
     $pg.Sections.RemoveAt($i)
 }
 $pg.Save()
 $page = Set-PnPPage -Identity $pg -Publish
 Disconnect-PnPOnline

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

Manifest 1.7.0 PnP.PowerShell

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

  • [X ] Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify
@gautamdsheth
Copy link
Collaborator

You need to save the page as well after removing the sections:

$pg = Get-PnPPage -Identity "Home" $sectionsCount = $pg.Sections.Count for($i=$sectionsCount-1; $i -ge 0; $i--) { write-host $i $pg.Sections.RemoveAt($i) } $pg.Save()

Only after that will the page be actually saved. Can you try this and let us know ?

@Employee87
Copy link
Author

Employee87 commented Sep 17, 2021

Tried it, no errors, but also no changes on the page :( Sections still remain. I also did the publish code after the Save() too.

@Arturiby
Copy link

Arturiby commented Dec 1, 2021

The issue isn't fixed yet (1.8.0 version). I can confirm that Sections can not be removed.

There is an issue in the class PnP.Core.Model.SharePoint.Page

        ......
        private readonly List<CanvasSection> sections = new List<CanvasSection>(1);
        public List<ICanvasSection> Sections
        {
            get
            {
                return sections.Cast<ICanvasSection>().ToList();
            }
        }
        ......

The Sections property returns a copy (new reference) of private variable sections . The code $pg.Sections.RemoveAt($i) doesn't actually remove Section object from private variable sections.

Also this issue affects ConvertTo-PnPPage command. The parameter RemoveEmptySectionsAndColumns does nothing.

cc @jansenbe

@jansenbe jansenbe transferred this issue from pnp/powershell Dec 1, 2021
@jansenbe jansenbe self-assigned this Dec 1, 2021
@jansenbe jansenbe added area: pages API 📄 Working with modern pages bug Something isn't working labels Dec 1, 2021
@jansenbe
Copy link
Contributor

jansenbe commented Dec 1, 2021

@Arturiby: thanks for notifying me of this issue. I've fixed this and the next nightly PowerShell version will have it included.

FYI @Employee87 / @gautamdsheth

@jansenbe jansenbe closed this as completed Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: pages API 📄 Working with modern pages bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants