Forum Discussion

ConstantinLotz's avatar
ConstantinLotz
Copper Contributor
Feb 26, 2023

Site Columns created by PNP Powershell not showing up in Highlighted Content Webpart

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

  • Hi ConstantinLotz 


    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

  • SvenSieverding's avatar
    SvenSieverding
    Bronze Contributor

    Hi ConstantinLotz 


    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

    • ConstantinLotz's avatar
      ConstantinLotz
      Copper Contributor
      Hi Sven,
      your are my man! It seems the highlighted content webpart does just not allow to select for multiuser. Because it was the first field I've not tried to create other types. But for example with Choice Fields it seems working 🙂
      Thanks a lot for getting my mind clear!
      Kind regards,
      Constantin
      • SvenSieverding's avatar
        SvenSieverding
        Bronze Contributor
        🙂 I'm glad i could help....
        That "Highlighted Content" webpart is sometimes very confusing, although it looks to easy

Resources