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

Add-PnPView does not support Aggregations? #2237

Closed
san-goyal opened this issue Sep 6, 2019 · 7 comments
Closed

Add-PnPView does not support Aggregations? #2237

san-goyal opened this issue Sep 6, 2019 · 7 comments
Labels
status:fixed-next-drop Issue will be fixed in upcoming release.

Comments

@san-goyal
Copy link

Environment: SharePoint online
PowerShell Module: SharePointPnPPowerShellOnline
Module version: 3.12.1908.1
Cmdlet: Add-PnPView
Problem: Aggregations parameter is not available

I want to create a new list view with aggregations on field (like sum of number column). I don't find any parameter to accept aggregations on Add-PnPView cmdlet.

PnP core supports aggregations - pnp/PnP-Sites-Core#924

Is aggregations are not available yet? or there is some other way to do it?

@ghost
Copy link

ghost commented Sep 6, 2019

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

@ghost ghost added the Needs: Triage 🔍 label Sep 6, 2019
@san-goyal san-goyal changed the title Add-PnPView does not support for Aggregations? Add-PnPView does not support Aggregations? Sep 6, 2019
@danielcecil
Copy link
Contributor

Hi @SanMSTech, how would you envisage this to work? You correctly pointed out that Aggregations can be added to the View XML so what would the command look like to you?

You may know that you can add fields using XML with Add-PnPFieldFromXml so would a similar command for Views meet your need?

@san-goyal
Copy link
Author

@danielcecil Thanks for reply.

I have used Add-PnPFieldFromXml to create new field to list. But i could not find PnP cmdlet to add view with aggregation.

Following is the CSOM code snippet to add new view with "Aggregations". I want to achieve similar functionality with PnP.
using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
{
List targetList = clientcontext.Web.Lists.GetByTitle("List Name");
ViewCollection viewCollection = targetList.Views;
clientcontext.Load(viewCollection);
ViewCreationInformation viewCreationInformation = new ViewCreationInformation();
viewCreationInformation.Title = "View Name";
viewCreationInformation.ViewTypeKind = ViewType.Html;
viewCreationInformation.RowLimit = 10;
viewCreationInformation.Query = "<Where><Eq><FieldRef Name = 'Location' /><Value Type = 'Text'>India</Value></Eq></Where>";
string CommaSeparateColumnNames = "Column name 1, column Name 2, Column Name 3";
viewCreationInformation.ViewFields = CommaSeparateColumnNames.Split(',');
View listView = viewCollection.Add(viewCreationInformation);
clientcontext.ExecuteQuery();
listView.Aggregations = "<FieldRef Name='Title' Type='COUNT'/>";
listView.Update();
clientcontext.ExecuteQuery();
}

Currently it looks like Add-PnPView does not support Aggregations.
Add-PnPView
-List <ListPipeBind>
-Title <String>
-Fields <String[]>
[-Query <String>]
[-ViewType <ViewType>]
[-RowLimit <UInt32>]
[-Personal [<SwitchParameter>]]
[-SetAsDefault [<SwitchParameter>]]
[-Paged [<SwitchParameter>]]
[-Web <WebPipeBind>]
[-Connection <SPOnlineConnection>]

What you think to add this last piece of Aggregations to PnP cmdlet to fully support list object model?

@danielcecil
Copy link
Contributor

Hi @SanMSTech, seems reasonable to add the functionality to both Add-PnPView and Set-PnPView commands. The easiest way for now would be to simply pass the XML definition through, for example:

Add-PnPView -List $list -Title "Documents" -Fields "Title" -Aggregations "<FieldRef Name='Title' Type='COUNT'/>"

So that would make it possible, but probably not the most user friendly way - any suggestions of what the command might look like baring in mind you can have multiple aggregations on a view?

@san-goyal
Copy link
Author

Hi @danielcecil , example looks perfect. Thank you.

How long you think it should take to be available? I want to try it out by this week.

@danielcecil
Copy link
Contributor

Hi @SanMSTech, I only submitted a pull request so it has to be accepted by the owners and tested before it goes into production. They usually do a monthly build (last one was a few days ago) so it's likely to be a few weeks even if it gets accepted.

However, you can fork the respository from the above pull request and compile a version for yourself if you need it (instructions are here: https://github.com/SharePoint/PnP-PowerShell)

@KoenZomers
Copy link
Collaborator

Sorry for the delay in getting PR #2257 checked and merged which should fix this issue. It has been validated and will be released in the next PnP PowerShell release around the 9th of February 2020. Closing this issue. Feel free to reopen if it turns out the issue wasn't fixed with this upcoming release.

@KoenZomers KoenZomers added status:fixed-next-drop Issue will be fixed in upcoming release. and removed Needs: Triage 🔍 labels Jan 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:fixed-next-drop Issue will be fixed in upcoming release.
Projects
None yet
Development

No branches or pull requests

3 participants