diff --git a/src/Commands/Model/SharePoint/NavigationNode.cs b/src/Commands/Model/SharePoint/NavigationNode.cs index 622bdc29a..14f6de5d2 100644 --- a/src/Commands/Model/SharePoint/NavigationNode.cs +++ b/src/Commands/Model/SharePoint/NavigationNode.cs @@ -16,7 +16,7 @@ public sealed class NavigationNode public bool IsHidden { get; set; } public bool IsTitleForExistingLanguage { get; set; } public string Key { get; set; } - public List Nodes { get; set; } + public List Nodes { get; set; } public int NodeType { get; set; } public bool? OpenInNewWindow { get; set; } public string SimpleUrl { get; set; } diff --git a/src/Commands/Navigation/AddNavigationNode.cs b/src/Commands/Navigation/AddNavigationNode.cs index fcaf58438..2f76db37d 100644 --- a/src/Commands/Navigation/AddNavigationNode.cs +++ b/src/Commands/Navigation/AddNavigationNode.cs @@ -124,7 +124,8 @@ protected override void ExecuteCmdlet() CurrentWeb.EnsureProperties(w => w.Url); var menuState = Utilities.REST.RestHelper.GetAsync(Connection.HttpClient, $"{CurrentWeb.Url}/_api/navigation/MenuState", ClientContext.GetAccessToken(), false).GetAwaiter().GetResult(); - var currentItem = menuState?.Nodes?.Where(t => t.Key == addedNode.Id.ToString()).FirstOrDefault(); + var currentItem = menuState?.Nodes?.Select(node => SearchNodeById(node, addedNode.Id)) + .FirstOrDefault(result => result != null); if (currentItem != null) { currentItem.OpenInNewWindow = OpenInNewTab.ToBool(); @@ -150,5 +151,16 @@ protected override void ExecuteCmdlet() throw new Exception("Unable to define Navigation Node collection to add the node to"); } } + + private static Model.SharePoint.NavigationNode SearchNodeById(Model.SharePoint.NavigationNode root, int id) + { + if (root.Key == id.ToString()) + { + return root; + } + + return root.Nodes.Select(child => SearchNodeById(child, id)).FirstOrDefault(result => result != null); + } + } }