pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
987 stars 665 forks source link

Get-PnPWebPartProperty - Set WebPartTitle #2022

Closed sohailmerchant closed 4 years ago

sohailmerchant commented 5 years ago
  1. Is the issue related to the cmdlet itself, its parameters, the syntax, or do you suspect it is the code of the cmdlet that is causing the issue? Then please continue reporting the issue in this repo.

I am adding webpart on the modern page Add-PnPClientSideWebPart -Page $newpage -DefaultWebPartType “People” -Section 2 -Column 2 -WebPartProperties @{title=”People”}

and later in the process setting the PropertiesJson like Set-PnPClientSideWebPart -Page $newpage -Identity $wp.InstanceId -PropertiesJson '{"properties": {"layout":1,"persons":[{"id":"admin@tenant.onmicrosoft.com","upn":"","role":"admin@tenant.onmicrosoft.com","department":"","phone":"","sip":""}]}, "serverProcessedContent": {"htmlStrings":{},"searchablePlainTexts":{"title":"","persons[0].name":"SharePointer","persons[0].email":"admin@tenant.onmicrosoft.com"},"imageSources":{},"links":{}}, "dynamicDataPaths": {}, "dynamicDataValues": {}}'

After setting the PropertiesJson the Title for the webpart get removed. I thought I could get the Get-PnPWebPartProperty -Identity $p.InstanceId[0] and set it again but Get-PnPWebProperty doesn't seem to be working.

Expected behavior

I thought Get-PnPWebPartProperty would return a JsonProperties of a webpart which can be set.

Actual behavior

I get either "Get-PnPWebPartProperty : File Not Found." or "Get-PnPWebPartProperty : Specified argument was out of the range of valid values.". I have tried various combination of sites/pnpsite1/SitePages/TestPage7.aspx or TestPage7.aspx and /SitePages/TestPage7.aspx nothing seem to work.

Which version of the PnP-PowerShell Cmdlets are you using?

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

How did you install the PnP-PowerShell Cmdlets?

heinrich-ulbricht commented 5 years ago

Hm I think Get-PnPWebPartProperty (and Get-PnPWebPart) are used to get classic web parts, not modern web parts. The "out of range" error indicates that there is no classic web part with the given ID, which is correct.

You can use Get-PnPClientSideComponent -Page $newpage -InstanceId $wp.InstanceId to get the web part including it's properties.

sohailmerchant commented 4 years ago

@heinrich-ulbricht, Thanks. Get-PnPClientSideComponent is helpful but we don't have any Set- for this cmdlet.

I managed to resolve this by adding the title in the PropertiesJson like "title":"Title of the WebPart"}.

Urgeoverkill commented 4 years ago

@heinrich-ulbricht, Thanks. Get-PnPClientSideComponent is helpful but we don't have any Set- for this cmdlet.

I managed to resolve this by adding the title in the PropertiesJson like "title":"Title of the WebPart"}.

Can you please expound on this. I have been strugling to find a method to set a web part propery in sharepoint online with powershell. how did you add the Json components ( and which command did you add it to)