From 0d7647eb9255821e23b6f408efc548eb358441af Mon Sep 17 00:00:00 2001 From: Erwin van Hunen Date: Fri, 11 May 2018 16:02:32 +0200 Subject: [PATCH] Added InSiteHierarchy --- CHANGELOG.md | 1 + Commands/Fields/GetField.cs | 54 ++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a36b3141..b312c720c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added - Added -CollapseSpecification option to Submit-PnPSearchQuery +- Added -InSiteHierarchy to Get-PnPField to search for fields in the site collection ### Changed - Fix for issue where using Add-PnPFile and setting Created and Modified did not update values diff --git a/Commands/Fields/GetField.cs b/Commands/Fields/GetField.cs index 353794558..c4133c14d 100644 --- a/Commands/Fields/GetField.cs +++ b/Commands/Fields/GetField.cs @@ -32,6 +32,9 @@ public class GetField : PnPWebRetrievalsCmdlet [Parameter(Mandatory = false, HelpMessage = "Filter to the specified group")] public string Group; + [Parameter(Mandatory = false, ValueFromPipeline = false, HelpMessage = "Search site hierarchy for fields")] + public SwitchParameter InSiteHierarchy; + protected override void ExecuteCmdlet() { if (List != null) @@ -67,8 +70,10 @@ protected override void ExecuteCmdlet() { if (!string.IsNullOrEmpty(Group)) { - WriteObject(fieldCollection.Where(f => f.Group.Equals(Group, StringComparison.InvariantCultureIgnoreCase)),true); - } else { + WriteObject(fieldCollection.Where(f => f.Group.Equals(Group, StringComparison.InvariantCultureIgnoreCase)), true); + } + else + { WriteObject(fieldCollection, true); } } @@ -81,15 +86,36 @@ protected override void ExecuteCmdlet() { if (Identity.Id == Guid.Empty && string.IsNullOrEmpty(Identity.Name)) { - ClientContext.Load(SelectedWeb.Fields, fc => fc.IncludeWithDefaultProperties(RetrievalExpressions)); + if (InSiteHierarchy.IsPresent) + { + ClientContext.Load(SelectedWeb.AvailableFields, fc => fc.IncludeWithDefaultProperties(RetrievalExpressions)); + } + else + { + ClientContext.Load(SelectedWeb.Fields, fc => fc.IncludeWithDefaultProperties(RetrievalExpressions)); + } ClientContext.ExecuteQueryRetry(); if (!string.IsNullOrEmpty(Group)) { - WriteObject(SelectedWeb.Fields.Where(f => f.Group.Equals(Group, StringComparison.InvariantCultureIgnoreCase)), true); + if (InSiteHierarchy.IsPresent) + { + WriteObject(SelectedWeb.AvailableFields.Where(f => f.Group.Equals(Group, StringComparison.InvariantCultureIgnoreCase)).OrderBy(f => f.Title), true); + } + else + { + WriteObject(SelectedWeb.Fields.Where(f => f.Group.Equals(Group, StringComparison.InvariantCultureIgnoreCase)).OrderBy(f => f.Title), true); + } } else { - WriteObject(SelectedWeb.Fields, true); + if (InSiteHierarchy.IsPresent) + { + WriteObject(SelectedWeb.AvailableFields.OrderBy(f => f.Title), true); + } + else + { + WriteObject(SelectedWeb.Fields.OrderBy(f => f.Title), true); + } } } else @@ -97,11 +123,25 @@ protected override void ExecuteCmdlet() Field field = null; if (Identity.Id != Guid.Empty) { - field = SelectedWeb.Fields.GetById(Identity.Id); + if (InSiteHierarchy.IsPresent) + { + field = SelectedWeb.AvailableFields.GetById(Identity.Id); + } + else + { + field = SelectedWeb.Fields.GetById(Identity.Id); + } } else if (!string.IsNullOrEmpty(Identity.Name)) { - field = SelectedWeb.Fields.GetByInternalNameOrTitle(Identity.Name); + if (InSiteHierarchy.IsPresent) + { + field = SelectedWeb.AvailableFields.GetByInternalNameOrTitle(Identity.Name); + } + else + { + field = SelectedWeb.Fields.GetByInternalNameOrTitle(Identity.Name); + } } ClientContext.Load(field, RetrievalExpressions); ClientContext.ExecuteQueryRetry();