Add-SPOView breaks View Menu #320

Closed
donshults opened this Issue May 11, 2016 · 3 comments

Comments

Projects
None yet
5 participants
@donshults

donshults commented May 11, 2016

After Creating a new List using the SPOList, I use the Add-SPOView to create new views on the List.
The new views are created, but they don't consistently show up on the List Menu above the actual list.
This behavior seems to manifest when two or more views are added.

The work around is to use the SP Gui Menu to create a New View, based on the one that was created by Add-SPOView. This new view acts correctly.

Expected behavior
After adding a view with Add-SPOView the view available in the View Menu Control on the View Page

Actual behavior

After adding a view with Add-SPOView Views are not available in the View Menu Control (See attached)

Also if this command is run in a script with multiple other items running before it, we get this error.
format-default : The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly
requested.
+ CategoryInfo : NotSpecified: (:) [format-default], CollectionNotInitializedException
+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Commands.FormatDefaultCommand

If the Command is run in ISE it does not return this error.

Steps to reproduce behavior
Write-Host "Adding Views"
$viewQuery = "SITE"
Add-SPOView -List $($targetListTitle) -Title "Sites" -Query $viewQuery -Fields "MigrationStatus","Notes","LinkTitle","WebUrl","DestinationWebUrl","Site Creator","Administrators","SubSites","Users","ContentOwner","Created Date","Accessed","Migration Status" -ViewType Grid -SetAsDefault
$viewQuery = ""
Add-SPOView -List $($targetListTitle) -Title "Sites & Content" -Query $viewQuery -Fields "MigrationStatus","Notes","LinkTitle","WebUrl","ListTitle","Count","ListUrl","DestinationWebUrl","DestinationListTitle","ContentOwner","LastModified","Created Date","DestinationListUrl","LastCreator","LastEditor","UniquePermissionsStatus","VersioningStatus","SizeMB","CType" -ViewType Grid

What version of the PnP-PowerShell Cmdlets are you using?
PNP PowerShell Online

*How did you install the PnP-PowerShell Cmdlets? *
Via MSI
menu1
Installer

@BaronSparky

This comment has been minimized.

Show comment
Hide comment
@BaronSparky

BaronSparky Jun 6, 2016

Hi Don,

Not an answer I am afraid but I have seen the same issue whenever trying to create "GRID" type views. This is apparent not just in the PnP code but also when just trying to use the CSOM to create the grid view "manually" via script. The view is not consistently shown in the quick access area but the view is created correctly if you select the lists "Current View" dropdown options.
I have found that if you open the view in something like SPD, add a space anywhere and then remove that space, i.e. just want to perform a save operation on the view, then it all seems to work correctly. Similarly, if you save your library with the view into a STP and then provision another list based on that STP, then it all works as expected.
It smells more like a product bug than a PnP bug imho.

Nige.

Hi Don,

Not an answer I am afraid but I have seen the same issue whenever trying to create "GRID" type views. This is apparent not just in the PnP code but also when just trying to use the CSOM to create the grid view "manually" via script. The view is not consistently shown in the quick access area but the view is created correctly if you select the lists "Current View" dropdown options.
I have found that if you open the view in something like SPD, add a space anywhere and then remove that space, i.e. just want to perform a save operation on the view, then it all seems to work correctly. Similarly, if you save your library with the view into a STP and then provision another list based on that STP, then it all works as expected.
It smells more like a product bug than a PnP bug imho.

Nige.

@tom-daly

This comment has been minimized.

Show comment
Hide comment
@tom-daly

tom-daly Feb 7, 2017

Not adding much to this but I'm also having same issue.

I'm executing a bunch of commands to provision a site and build it out. When adding a view it will throw an error. It creates the view like you have but the customer doesn't appreciate seeing the error.

It only happens after I create a new site like below. If the site already exists and I'm just deleting lists and recreating the lists then it works perfectly.

$rootWebUrlParam = "https://tdaly.sharepoint.com/sites/tdaly"
$newSiteTitleParam = "test2"
$newSiteUrlParam = "test2"

Connect-PnPOnline -Url $rootWebUrlParam -Credentials $cred
Remove-PnPWeb -Url $newSiteUrlParam -Force
New-PnPWeb -Title $newSiteTitleParam -Url $newSiteUrlParam -Template "CMSPUBLISHING#0" -InheritNavigation
Connect-PnPOnline -Url $rootWebUrlParam/$newSiteUrlParam -Credentials $cred

New-PnPList -Title "Calendar" -Template "Events" -OnQuickLaunch
New-PnPList -Title "Announcements" -Template "Announcements" -OnQuickLaunch
Add-PnPView -List "Announcements" -Title "Rollup" -Fields "Title","Body","Created" -RowLimit 5 -Query "<OrderBy><FieldRef Name=""Created"" Ascending=""False""/></OrderBy>"`

format-default : The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
+ CategoryInfo : NotSpecified: (:) [format-default], CollectionNotInitializedException
+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Commands.FormatDefaultCommand

tom-daly commented Feb 7, 2017

Not adding much to this but I'm also having same issue.

I'm executing a bunch of commands to provision a site and build it out. When adding a view it will throw an error. It creates the view like you have but the customer doesn't appreciate seeing the error.

It only happens after I create a new site like below. If the site already exists and I'm just deleting lists and recreating the lists then it works perfectly.

$rootWebUrlParam = "https://tdaly.sharepoint.com/sites/tdaly"
$newSiteTitleParam = "test2"
$newSiteUrlParam = "test2"

Connect-PnPOnline -Url $rootWebUrlParam -Credentials $cred
Remove-PnPWeb -Url $newSiteUrlParam -Force
New-PnPWeb -Title $newSiteTitleParam -Url $newSiteUrlParam -Template "CMSPUBLISHING#0" -InheritNavigation
Connect-PnPOnline -Url $rootWebUrlParam/$newSiteUrlParam -Credentials $cred

New-PnPList -Title "Calendar" -Template "Events" -OnQuickLaunch
New-PnPList -Title "Announcements" -Template "Announcements" -OnQuickLaunch
Add-PnPView -List "Announcements" -Title "Rollup" -Fields "Title","Body","Created" -RowLimit 5 -Query "<OrderBy><FieldRef Name=""Created"" Ascending=""False""/></OrderBy>"`

format-default : The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
+ CategoryInfo : NotSpecified: (:) [format-default], CollectionNotInitializedException
+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Commands.FormatDefaultCommand

@XopherDesign

This comment has been minimized.

Show comment
Hide comment
@XopherDesign

XopherDesign Apr 12, 2017

After a LOT of trial and error I've figured out a decent work around.
The issue is with the other views not with the new view.
After you create a new view with PowerShell you have to go through the other views pages and update the webpart. This example is server model PowerShell but it's easy to translate.
foreach ($vURL in ($web.Lists["Documents"].Views | Select ServerRelativeUrl)) { $file= $web.GetFile($vURL.ServerRelativeUrl) $WebPartManager = $web.GetLimitedWebPartManager( $file,  [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) #Fix quick edit ghost $WebPartManager.SaveChanges($WebPartManager.WebParts[0]); }

After a LOT of trial and error I've figured out a decent work around.
The issue is with the other views not with the new view.
After you create a new view with PowerShell you have to go through the other views pages and update the webpart. This example is server model PowerShell but it's easy to translate.
foreach ($vURL in ($web.Lists["Documents"].Views | Select ServerRelativeUrl)) { $file= $web.GetFile($vURL.ServerRelativeUrl) $WebPartManager = $web.GetLimitedWebPartManager( $file,  [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) #Fix quick edit ghost $WebPartManager.SaveChanges($WebPartManager.WebParts[0]); }

@spdevdocs spdevdocs closed this Apr 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment