Adventures in PnP PowerShell provisioning templates
Has this ever happened to you? I had built a custom list with a custom view. To be more precise, I had basically lifted Chris Kent's sample here for a custom FAQ and dropped this on the page and the client was thrilled with it just as it is. Thanks Chris! Here's what the FAQ page looked like on the template site:
|Not a bad looking FAQ list, right?
But this is just the beginning! This was my template. I need lots of sites to have this same FAQ page as a starting point, and it needs to look this good too.
So, onto provisioning with Powershell and PnP! At first I was running this:
Looks familiar right? Well pretty much everything was working great except for this:
|Not so good. Also don't focus on the color difference lol
What the heck was going on here? The view and the list were migrating just fine, but that view was not getting applied! Or, was it? I noticed this in the List part properties:
|Something is amiss
See anything off? Nothing is selected in the view drop down, even though it is selected in the my template site.
Acting on a Hunch
So here was my hunch. Perhaps, the pages are getting deployed before the custom list and custom view, sooo when the page gets made, there's no view to select, which is why it looks like the above. I acted on this hunch, by doing the following:
I split out just the FAQ list portion from the full
Get-PnPProvisioningTemplate - essentially doing 2 Gets: one for the list only and one for everything else. Here's what that looked like:
Now you have 2 files. But there's 1 trick to this, if you want it to work in your favor. You need to open up the XML file for everything, and delete just the
ListInstance node for the list (in my case, FAQ) from the XML file. So you can't easily do this all in one full script. You'd have to keep your pulls separate from your applies because of this manual intervention.
Then I applied my 2 files separately as well, starting with the lists first:
And, viola! My FAQ list was displaying as expected on the page, because the view was already found for the web part property because it already existed.