Forum Discussion

wit4r7's avatar
wit4r7
Brass Contributor
May 13, 2020

Empty space between Sections when creating Webparts via PnP

Hey,

 

I am still in the process of creating a script that automatically makes various adjustments when a new site is created.

 

Among other things 3 webparts should be added. 1 list with a custom JSON formatting, 1 group calendar and "Highlight Content".

 

This all works very well in itself, but I have a big empty gap within the first sections. As soon as I click on Edit in the GUI the gap is gone.

 

Do I have an error in the script or do I have to add a separate command at the end that it renders the page again?

 

Here is an extract from the script and the result

 

 

#Add needed Webparts
$list = Get-PnPList -Identity $ListName
$views = Get-PnPProperty -ClientObject $list -Property Views

foreach ($view in $views) {
    if ($view.Title -eq $ViewName) {
        $viewID = $view.id
    }
}

Add-PnPClientSidePageSection -Page $page -SectionTemplate TwoColumn 
Add-PnPClientSideWebPart -Page $page -DefaultWebPartType “List” -Section 1 -Column 1 -WebPartProperties @{isDocumentLibrary="false";selectedListId=$list.Id; selectedViewId=$viewID; hideCommandBar="true"; webpartHeightKey="4"}
Add-PnPClientSideWebPart -Page $page -DefaultWebPartType "GroupCalendar" -Section 2 -Column 2 -WebPartProperties @{title=”Upcoming Appointment”;showPerPage="3"; selectedGroupId=$groupID; accessType="private"}

$JSONMostRecent = '{"query":{"contentLocation":4,"contentTypes":[1],"sortType":1,"filters":[{"filterType":1,"value":"","values":[]}],"documentTypes":[99],"advancedQueryText":""},"templateId":1,"maxItemsPerPage":8,"hideWebPartWhenEmpty":false,"sites":[],"queryMode":"Basic","layoutId":"Card","dataProviderId":"List","webId":"$($web.id)","siteId":"$($site.id)","lastListId":"$($list.id)","listId":"$($list.id)","listTitle":"Documents","caml":"<View Scope=\"RecursiveAll\"><Query><Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Integer\">0</Value></Eq></Where><OrderBy><FieldRef Name=\"Modified\" Ascending=\"false\" /></OrderBy></Query><ViewFields><FieldRef Name=\"Editor\" /><FieldRef Name=\"FileLeafRef\" /><FieldRef Name=\"File_x0020_Type\" /><FieldRef Name=\"ID\" /><FieldRef Name=\"Modified\" /><FieldRef Name=\"Title\" /><FieldRef Name=\"UniqueID\" /><FieldRef Name=\"_ShortcutUrl\" /></ViewFields><RowLimit Paged=\"false\">8</RowLimit></View>"}'

Add-PnPClientSideWebPart -Page $page -DefaultWebPartType "ContentRollup" -Section 2 -Column 1 -WebPartProperties $JSONMostRecent

 

 

 

 

Many thanks for your answers and advice.

 

Best regards

  • wit4r7's avatar
    wit4r7
    Brass Contributor

    Has nobody an idea?

    The problem still exists. I figured out that the problem is the list webpart. The height of the webpart is not dynamic when creating it via PowerShell.

     

    Best regards

Resources