powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] Set-PnPPageWebPart set page property

Open HeKr09 opened this issue 5 years ago • 10 comments

Reporting an Issue or Missing Feature

I want to add a page property but I am not able to.

Expected behavior

I expect to just add the field by this cmdlet.

Actual behavior

I get an error:

Set-PnPPageWebPart : '=' is invalid after a single JSON value. Expected end of data. LineNumber: 0 | BytePositionInLine: 18.
At line:1 char:1
+ Set-PnPPageWebPart -Page $page -Identity 4e17657e-beb5-4511-b4d5-49c7 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPPageWebPart], JsonReaderException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Pages.SetClientSideWebPart

Steps to reproduce behavior

$item = Get-PnPListItem -List "Site Pages" -Id 3
$page.Controls[0].PropertiesJson
# {"title":"","selectedFieldIds":["23f27201-bee3-471e-b2e7-b64fd8b7ca38"],"availableFields":[]}
Set-PnPPageWebPart -Page $page -Identity 4e17657e-beb5-4511-b4d5-49c73d71fedc -PropertiesJson "`"selectedFieldIds`"=`"[`"23f27201-bee3-471e-b2e7-b64fd8b7ca38`",`"ae08775f-c1d3-482e-93f5-79b833f393de`"]`""

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

1.5.0

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

  • [x] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

HeKr09 avatar Jul 05 '21 08:07 HeKr09

I also tried ":" but got a similar error. According to the documentation I don't know what should be wrong here?!

HeKr09 avatar Jul 05 '21 08:07 HeKr09

This also broke for me when attempting to update a Markdown webpart. It worked a couple of weeks ago, not sure what changed. I used this for reference and it worked great.

https://github.com/pnp/PnP-PowerShell/issues/2336

elementlu avatar Jul 07 '21 02:07 elementlu

I'm assuming there is no alternate way to update the markdown webpart via PNP powershell? is there a way to install an older version of pnp?

elementlu avatar Jul 13 '21 20:07 elementlu

Okay. Worked with Set-PnpClientSideWebPart but why doesn't it work with Set-PnpWebPart?

HeKr09 avatar Jul 22 '21 14:07 HeKr09

confirmed - changing my script to use the old cmdlet worked for me as well. didn't update pnp to 1.7 yet as it says this cmdlet will be removed in 1.5....

elementlu avatar Jul 27 '21 14:07 elementlu

i misspoke.

the commands don't work for me still. i happen to be on an older machine with the older pnp module setup. i will attempt everything again with 1.7 but as of right now this is not working still

elementlu avatar Jul 27 '21 17:07 elementlu

Confirming that this is still broken.

Had to find an older machine running SharePointPnPPowerShellOnline

elementlu avatar Aug 31 '21 03:08 elementlu

by the way the error I receive is:

Set-PnPPageWebPart : '0x0D' is invalid within a JSON string. The string should be correctly escaped. LineNumber: 0 | 
BytePositionInLine: 97.
At C:\Users\jlu\Desktop\PnP.Powershell\functions\Set-MarkDownWebPart.ps1:35 char:13
+             Set-PnPPageWebPart -Page $homePage -Identity $components[ ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPPageWebPart], JsonReaderException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Pages.SetClientSideWebPart

elementlu avatar Aug 31 '21 13:08 elementlu

My problem is solved. Went to the SharePoint disqus channel and was told that the JSON parser was changed when PnP was upgraded to .net standard.

We resolved the issue by added new escape lines for each line.

elementlu avatar Sep 01 '21 19:09 elementlu

I had to add { } -PropertiesJson "{"property":"value"}"

XopherDesign avatar Feb 09 '24 22:02 XopherDesign