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

Fix: Add List View Aggregations #2257

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Commands/Lists/AddView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ namespace SharePointPnP.PowerShell.Commands.Lists
[CmdletExample(
Code = @"Add-PnPView -List ""Demo List"" -Title ""Demo View"" -Fields ""Title"",""Address"" -Paged",
Remarks = @"Adds a view named ""Demo view"" to the ""Demo List"" list and makes sure there's paging on this view.",
SortOrder = 2)]
SortOrder = 2)]
[CmdletExample(
Code = @"Add-PnPView -List ""Demo List"" -Title ""Demo View"" -Fields ""Title"",""Address"" -Aggregations ""<FieldRef Name='Title' Type='COUNT'/>""",
Remarks = @"Adds a view named ""Demo view"" to the ""Demo List"" list and sets the totals (aggregations) to Count on the Title field.",
SortOrder = 3)]
public class AddView : PnPWebCmdlet
{
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The ID or Url of the list.")]
Expand Down Expand Up @@ -45,7 +49,10 @@ public class AddView : PnPWebCmdlet
public SwitchParameter SetAsDefault;

[Parameter(Mandatory = false, HelpMessage = "If specified, the view will have paging.")]
public SwitchParameter Paged;
public SwitchParameter Paged;

[Parameter(Mandatory = false, HelpMessage = "A valid XMl fragment containing one or more Aggregations")]
public string Aggregations;

protected override void ExecuteCmdlet()
{
Expand All @@ -54,6 +61,13 @@ protected override void ExecuteCmdlet()
{
var view = list.CreateView(Title, ViewType, Fields, RowLimit, SetAsDefault, Query, Personal, Paged);

if(Aggregations != null)
{
view.Aggregations = Aggregations;
view.Update();
list.Context.Load(view);
list.Context.ExecuteQueryRetry();
}
WriteObject(view);
}
}
Expand Down
18 changes: 16 additions & 2 deletions Commands/Lists/SetView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ namespace SharePointPnP.PowerShell.Commands.Fields
[CmdletExample(
Code = @"PS:> Set-PnPView -List ""Documents"" -Identity ""Corporate Documents"" -Fields ""Title"",""Created""",
Remarks = @"Updates the Corporate Documents view on the Documents library to have two fields",
SortOrder = 2)]
SortOrder = 3)]
[CmdletExample(
Code = @"PS:> Set-PnPView -List ""Documents"" -Identity ""Corporate Documents"" -Fields ""Title"",""Created"" -Aggregations ""<FieldRef Name='Title' Type='COUNT'/>""",
Remarks = @"Updates the Corporate Documents view on the Documents library and sets the totals (aggregations) to Count on the Title field",
SortOrder = 4)]
public class SetView : PnPWebCmdlet
{
[Parameter(Mandatory = false, Position = 0, HelpMessage = "The Id, Title or Url of the list")]
Expand All @@ -39,6 +43,9 @@ public class SetView : PnPWebCmdlet
[Parameter(Mandatory = false, HelpMessage = "An array of fields to use in the view. Notice that specifying this value will remove the existing fields")]
public string[] Fields;

[Parameter(Mandatory = false, HelpMessage = "A valid XMl fragment containing one or more Aggregations")]
public string Aggregations;

protected override void ExecuteCmdlet()
{
List list;
Expand Down Expand Up @@ -119,7 +126,14 @@ protected override void ExecuteCmdlet()
view.Update();
ClientContext.ExecuteQueryRetry();
}

if(Aggregations != null)
{
view.Aggregations = Aggregations;
view.Update();
ClientContext.Load(view);
ClientContext.ExecuteQueryRetry();
}
WriteObject(view);
}
}
}