Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1562 from erwinvanhunen/dev
Browse files Browse the repository at this point in the history
Added InSiteHierarchy
  • Loading branch information
erwinvanhunen committed May 11, 2018
2 parents ee406db + 0d7647e commit 2e7fb31
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 47 additions & 7 deletions Commands/Fields/GetField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class GetField : PnPWebRetrievalsCmdlet<Field>
[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)
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -81,27 +86,62 @@ 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
{
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();
Expand Down

0 comments on commit 2e7fb31

Please sign in to comment.