Add-PnpView not applying filter

Jurgen Verhelst 326 Reputation points
2020-12-27T16:02:46.013+00:00

Hi

trying to get a filtered view in a modern teams site template to the default documents lib
before I could just create a template (get-pnpProvisioningTemplate) , then apply that to the new site, but now it complains that documents already exist. before it just added the new fields and views on top of it.

so now I removed the documents lib from the xml template and try to recreate the fields and views after the site creation and before applying the xml template

but, when I try to add the view, it is created but the filter does something funky:

used code:

# Add Columns to Documents Library  
Add-PnPField -List "Documents" -DisplayName "Show In Home" -InternalName "Show In Home" -Type boolean -AddToDefaultView  
  
# Add View to Documents Library  
Add-PnPView -Fields "DocIcon","LinkFilename","Modified","Editor","_UIVersionString","FileSizeDisplay" -List "Documents" -Title "Show In Home" -Query "<OrderBy><FieldRef Name='Prio' Ascending='false' /></OrderBy><Where><Eq><FieldRef Name = 'Show In Home' /><Value Type = 'Boolean'>1</Value></Eq></Where>" | out-Null  
 

(I added the out-Null because the runbook tried to run three times otherwise)

The view gets created but the filter where "Show in home" is equal to '1' is not working
the field is None instead of 'Show In Home' and also it does not understand '1', it needs to be Yes before I can save the view in SPO

I tried using 'Yes' in de CAML but that does not take

any ideas?

also if someone could show me how I could type the add-pnpview in several lines so its not that long would be nice too :)

here is the screenshot how it looks in SPO when the powershell ran:
51452-screenshot-2020-12-27-164402.png

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,615 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,362 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 96,266 Reputation points MVP
    2020-12-27T21:28:06.31+00:00

    I am not 100% if the -InternalName is working with a space in the value:

     # Add Columns to Documents Library
     Add-PnPField -List "Documents" -DisplayName "Show In Home" -InternalName "ShowInHome" -Type boolean -AddToDefaultView
    
     # Add View to Documents Library
     Add-PnPView -Fields "DocIcon","LinkFilename","Modified","Editor","_UIVersionString","FileSizeDisplay" -List "Documents" -Title "Show In Home" -Query "<OrderBy><FieldRef Name='Prio' Ascending='false' /></OrderBy><Where><Eq><FieldRef Name = 'ShowInHome' /><Value Type = 'Boolean'>1</Value></Eq></Where>" | out-Null
    

    Maybe this is working as expected?


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 96,266 Reputation points MVP
    2020-12-27T22:53:23.07+00:00

    I googled for the error message you posted (just the beginning of the error message).
    And I found the solution with adding the command in a variable a couple of times.

    If the issue is fixed by "just waiting a little bit" I would accept that. Maybe there is some magic ongoing behind.


    Kind regards
    Andreas Baumgarten

    0 comments No comments