Feb 25 2023 05:41 PM
Hi there,
i'm getting stuck in creating some custom colums for the "Site Pages" library - to deploy some colums automatically.
I can create collumns by pnp like this:
$siteurl = "https://domain.sharepoint.com/sites/2501"
Connect-PnPOnline -Url $SiteURL -Interactive
$SitePagesList = Get-PNPList |? { $_.Title -eq "Websiteseiten" -or $_.Title -eq "SitePages" }
$DisplayName = "Redakteur2"
$PNPField = Add-PnPField -List $SitePagesList -InternalName $DisplayName -DisplayName $DisplayName -Type User -AddToDefaultView -Required -AddToAllContentTypes
[XML]$SchemaXml = $PNPField.SchemaXml
$SchemaXml.Field.SetAttribute("Mult","TRUE")
$SchemaXml.Field.SetAttribute("UserDisplayOptions","NamePhoto")
$OuterXML = $SchemaXml.OuterXml.Replace('Field Type="User"','Field Type="UserMulti"')
Set-PnPField -List $SitePagesList -Identity $PNPField.Id -Values @{SchemaXml =$OuterXML} -UpdateExistingLists
They show up correctly under site pages:
But I cant select the column Redakteur in the Webpart "Highlighted Content":
In the webpart only from hand created properties show up. Am i wrong here somehow?
If I compare the ouput of both fields from:
Get-PnPField -List $SitePagesList -Identity "XXXXXXX-be4a-429b-9b2a-6207e7f85535" | fl *
I dont see a big difference. I've aswell tried creating the field and setting the difference options like UserSelectionMode. But this didn't make a difference.
Does anybody out there has an idea what is wrog here?
Or otherwise how I can deploy some custom colums for the existing site pages library?
I've tried this aswell with the command below, but this creates me a new Page Library with the same name. Seems a bug in PNP Powershell....
$siteScript = ....
"verb": "createSPList",
"listName": "Site Pages",
"templateType": 119,
"subactions": [
{
"displayName": "Redakteur",
"isRequired": true,
"addToDefaultView": false,
"fieldType": "User",
"enforceUnique": false,
"verb": "addSPField"
},
.....
Invoke-PnPSiteScript -WebUrl $siteurl -Script $siteScript
Kind regards,
Constantin
Feb 26 2023 05:27 AM
Solution
Your code works.
After line 5 you have a "single user field" that correctly shows up in the "Highlighted Contents" webpart.
But after you switch that webpart to a "multi user field" it stops showing up in the "Highlighted Contents" webpart.
A "multi user field" did not show up in the "Highlighted Contents" webpart even if i created it manually, so i think that that webpart does not support "multi user fields".
But in this case you can alternatively just ditch the "Highlighted Contents" webpart and use a normal "Document library" webpart instead. Here you can filter by "multi user fields".
If you don't like the "List"- or "Tile"- Layout, then you can apply a JSON List formatting like this "https://github.com/pnp/List-Formatting/tree/master/view-samples/document-library-gallery-card"
Best Regards,
Sven
Mar 03 2023 01:03 AM
Mar 03 2023 01:45 AM
Feb 26 2023 05:27 AM
Solution
Your code works.
After line 5 you have a "single user field" that correctly shows up in the "Highlighted Contents" webpart.
But after you switch that webpart to a "multi user field" it stops showing up in the "Highlighted Contents" webpart.
A "multi user field" did not show up in the "Highlighted Contents" webpart even if i created it manually, so i think that that webpart does not support "multi user fields".
But in this case you can alternatively just ditch the "Highlighted Contents" webpart and use a normal "Document library" webpart instead. Here you can filter by "multi user fields".
If you don't like the "List"- or "Tile"- Layout, then you can apply a JSON List formatting like this "https://github.com/pnp/List-Formatting/tree/master/view-samples/document-library-gallery-card"
Best Regards,
Sven