Staff sample using List Formatting

Today, we will review and use a List formatting, one of the features that SharePoint and apply it via PnP PowerShell. You can use it to apply to multiple sites with this automated process. The concept of this sample is that you have a Team inside your organization and you want to share the contacts of the persons on your SharePoint using a list. The PowerShell created will allow you to create all the required assets for using this sample.

Sample of each element of the list

All the required PowerShell, as well as the JSON file, will be available on the GitHub. The link for this sample is below. On this example, the PnP PowerShell will create the list, all the required columns the PowerShell and add the list formatting.

If you intend to check the examples of the List Formatting from the community, please verify the following link below:

One of the Columns is created using the XML because to get the Picture and additional information the User property requires a special ShowField . You just need to add content to the list to see the cards.

The first step is to create a file on your desktop which will contain the JSON that we will apply to the list. Create a copy of the JSON on the GitHub ViewFormatting.json and save it on your machine, it’ll be used by PowerShell to apply to the SharePoint list View.

$site     = "https://contoso.sharepoint.com" #Site where the list will be created.
$nameList = "Project Staff" # Name of the List
$JsonPath = "C:\Users\USER\Desktop\ViewFormatting.txt" #Path to the Json File

$JSONFile = Get-Content $JsonPath 

$JSONFile | ConvertFrom-Json |Out-Null
$fieldXml = '<Field Type="User" Name="Person" DisplayName="Person" ID="{4dbd3482-af24-4319-913d-31e94b33912d}" Group="" Required="FALSE" SourceID="{56606dc3-9123-4fcb-a8be-5b20378eee20}" StaticName="Person" ColName="int1" RowOrdinal="0" EnforceUniqueValues="FALSE" ShowField="NameWithPictureAndDetails" UserSelectionMode="PeopleAndGroups" UserSelectionScope="0" Version="1" />'

Connect-PnPOnline -Url $site -UseWebLogin 

New-PnPList -Title $nameList -Template GenericList
Add-PnPField -List $nameList -DisplayName "LinkedIn" -InternalName "LinkedIn" -Type URL
Add-PnPField -List $nameList -DisplayName "Job Title" -InternalName "JobTitle" -Type Text
Add-PnPField -List $nameList -DisplayName "Phone Number" -InternalName "PhoneNumber" -Type Text
Add-PnPFieldFromXml -List $nameList -FieldXml $fieldXml

Set-PnPView -List $nameList -Identity "All Items" -Fields "Title","LinkedIn","JobTitle","PhoneNumber","Person"

$view = Get-PnPView -List $nameList -Identity "All Items" -Includes "CustomFormatter"
$view.CustomFormatter = $JSONFile
$view.Update()
Invoke-PnPQuery -RetryWait 10

Conclusion

This sample is an adaption of this view formatting with the addition of the PowerShell to add quickly this to multiple sites – https://github.com/SharePoint/sp-dev-list-formatting/tree/master/view-samples/profile-card.

References

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *