pnp / PnP-PowerShell

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

Add-PnPNavigationNode fails when adding a link to a footer #2880

Closed jooaij closed 4 years ago

jooaij commented 4 years ago

Notice: many issues / bugs reported are actually related to the PnP Core Library which is used behind the scenes. Consider carefully where to report an issue:

  1. Are you using Apply-PnPProvisioningTemplate or Get-PnPProvisioningTemplate? The issue is most likely related to the Provisioning Engine. The Provisioning engine is not located in the PowerShell repo. Please report the issue here: https://github.com/pnp/PnP-Sites-Core/issues.
  2. 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.
  3. If you think that the functionality might be related to the underlying libraries that the cmdlet is calling (We realize that might be difficult to determine), please first double check the code of the cmdlet, which can be found here: https://github.com/pnp/PnP-PowerShell/tree/master/Commands. If related to the cmdlet, continue reporting the issue here, otherwise report the issue at https://github.com/pnp/PnP-Sites-Core/issues

Reporting an Issue or Missing Feature

Issue

Expected behavior

New navigation links are expected to be created in target SharePoint site's footer.

Actual behavior

Links are not created. Error message raised by the commandlet is "The property or field 'ServerRelativeUrl' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested."

Steps to reproduce behavior

Error occurs when running lines of code such as: Connect-PnPOnline -Url $siteUrl Set-PnPFooter -Enabled:$true Add-PnPNavigationNode -Location Footer -Title $link.Title -Url $link.Url -External

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

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

3.24.2008.1

How did you install the PnP-PowerShell Cmdlets?

ghost commented 4 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

jackpoz commented 4 years ago

I opened a PR to PnP-Sites-Core to fix the issue.

In the meantime you can workaround the issue by calling Get-PnPWeb -Include ServerRelativeUrl before Add-PnPNavigationNode

Here's an example with the workaround: image

jooaij commented 4 years ago

Thanks for the workaround! That helped to add a single footer link (as in the simplified example), but in my full script I was adding multiple links on a site. For that purpose I had to modify it slightly:

$web = Get-PnPWeb -Include ServerRelativeUrl Set-PnPFooter -Enabled:$true foreach($link in $footerLinks){ Add-PnPNavigationNode -Location 'Footer' -Title $link.Title -Url $link.Url -External $web.Update() }