Open vaderj opened 3 years ago
It would have been easier to reproduce the issue if the provided steps included the creating of libraries and pages required, i.e. "ArticleWikiPages" and "/ArticleWikiPages/MAP-Sustainable-Basmati-India.aspx", and the webpart itself being added
I created a Wiki page, added a Documents webpart, retrieved the xml and called Add-PnPWebPartToWikiPage and it worked without errors
Connect-PnPOnline $siteUrl
$sourceUrl = "/sites/PS2921/SitePages/SourceWiki.aspx"
$targetUrl = "/sites/PS2921/SitePages/TargetWiki.aspx"
$webpartXml = Get-PnPWebPartXml -ServerRelativePageUrl $sourceUrl -Identity "Documents"
Add-PnPWebPartToWikiPage -ServerRelativePageUrl $targetUrl -Row 1 -Column 1 -XML $webpartXml
I tried experimenting a bit and turns out I was able to get a similar error when I created a WebPart Page
Are you sure you created a Wiki page as target of Add-PnPWebPartToWikiPage ?
I created a pull request at https://github.com/pnp/PnP-Sites-Core/pull/2762 to handle the case instead of throwing an exception. It still doesn't mean that Add-PnPWebPartToWikiPage will work on any page that is not of type "Wiki Page" (content type called with that name).
You can check if the page is of type wiki by comparing the content type or by checking if the field "WikiField" exists and is not null (there are probably more ways too but these are the ones on the top of my head)
So I was originally trying to use AddPnPWebPartToWikiPage to add to pages created by ShareGate, but I have since gone with a script which instead creates a new wikipage using Add-PnPWikiPage but I am still unable to use AddPnPWebPartToWikiPage to add a web part to the page
The -ServerRelativePageUrl variables - 1 is the full server relative URL, the other is relative to the site collection, without the leading '/' as described https://github.com/pnp/PnP-PowerShell/issues/848
Does the ArticleWikiPages library have a field called "WikiField" ? does the resulting Wiki page have the "WikiField" not null ? how did you create that library ?
My library does NOT contain a "WikiField" property but I do have a "Wiki Content", and when I created a new Wiki Page Library its the same way
New Wiki Page library:
I also tried adding a SLT field to my existing library called "WikiField" but the same error is still thrown
So I found the WikiField when I called it from get-pnplistitems and when I looked at the contents of one of the wikipages fom Add-PnpWikiPage: (sorry, I lost the screenshot on a different computer - it was only a single empty div)
But when I look at a brand new page made from the GUI in a wiki library, inside the div is:
<table id="layoutsTable" style="width:100%;"><tbody><tr style="vertical-align:top;"><td style="width:100%;"><div class="ms-rte-layoutszone-outer" style="width:100%;"><div class="ms-rte-layoutszone-inner" style="min-height:420px;"><p><br></p></div></div></td></tr></tbody></table><span id="layoutsData" style="display:none;">false,false,1</span>
So I added that to each new page after add-pnpwikipage is created, and the process appears to be working now .
Expected behavior
When using Add-PnPWebPartToWikiPage, and providing arguments -ServerRelativePageUrl -Xml $webPartXml -Row 1 -Column 1, I expect the command to complete successfully
Actual behavior
Please describe what you see instead. Please provide samples of HTML output or screenshots
Error received: Add-PnPWebPartToWikiPage : Value cannot be null. Parameter name: input At line:3 char:1
Variables:![image](https://user-images.githubusercontent.com/5408195/93401997-6683eb80-f838-11ea-8613-985155a3e261.png)
Steps to reproduce behavior
Please include complete code samples in-line or linked from gists
$url = "https://myTennent.sharepoint.com/sites/mySite" Connect-PnPOnline $url -UseWebLogin $items = Get-PnPListItem -List "ArticleWikiPages"
$templatePage = "/ArticleWikiPages/MAP-Sustainable-Basmati-India.aspx" $wp = (Get-PnPWebPart -ServerRelativePageUrl $templatePage)[0] $webPartXml = Get-PnPWebPartXml -ServerRelativePageUrl $templatePage -Identity $wp.Id
foreach($item in $items){ $thisUrl = $item.FieldValues.FileRef Add-PnPWebPartToWikiPage -ServerRelativePageUrl $thisUrl -XML $webPartXml -Row 1 -Column 1 }
Which version of the PnP-PowerShell Cmdlets are you using?
What is the version of the Cmdlet module you are running?
(you can retrieve this by executing
Get-Module -Name sharepointpnppowershell* -ListAvailable
) 3.25.2009.1How did you install the PnP-PowerShell Cmdlets?