Fix ViewTypeKind property being ignored when provisioning views #816
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix ViewTypeKind property being ignored by SPO when provisioning a new view and updating ListViewXml property during the same ExecuteQueryRetry() call. All views would have ViewType set to HTML before.
The code in this PR first creates the view, calls ExecuteQueryRetry(), then updates the ListViewXml property, then calls ExecuteQueryRetry(). This seems to be needed by serverside behavior of SPO, as ViewCreationInformation is filled with the same information in both cases.
Tests
The test was done with a view created from SPO List Settings with "Datasheet View" as base view and then exported with Get-PnPSiteTemplate. The xml template has these attributes:
Notice how the view provisioned before the fix has ViewType set to HTML and ListViewXml shows Type="HTML", even if the template has GRID
This is how the view looked on SPO, not grid view. A custom sorting by ID was added to test a different case than the standard view one:
This is the same view created using the same template after applying the fix from this PR. Notice how ViewType now is set to GRID and ListViewXml has Type="GRID":
SPO kept the same sorting by ID and the view is a grid view:
In an attempt to test it a bit deeper I created a few views, exported them as pnp template, deleted the list and re-applied the template.
Case with default "All items" plus a new custom field "Category":
Case grouping by custom field "Category", sorted by ID descending:
Case filtering by custom field "Category" set to "Choice 2":
Case with Grid view:
Template used for the test cases:
views.zip