7 Oct 2019

Parenting

For the last month, I’ve been looking after my son on my own. My wife has been in China dealing with a family emergency, and due to its nature, it was thought best that she go alone. I am lucky enough to have an employer that could allow me to take unpaid leave to look after Matthew, and we are also lucky enough to be in a position financially to afford to take it.

For the past month Matthew and I have been together pretty much 24/7. It was pretty intense, and at times, an absolutely exhausting time. Our father/son relationship has deepened greatly, and my appreciation for the work done by my wife Mei in looking after Matthew has grown exponentially. I considered myself a pretty involved father before – I now know I was kidding myself.

Matthew playing with Duplo

Tomorrow I go back to my regular work, writing text files for a computer. Compared to parenting, it is by far the easier job of the two.  The past month has been tough at times – but so are most things that are worth doing. I suspect that in the future, I look back at this as one of the most productive times in my life.

3 Apr 2019

Setting Row and Column Formats in SharePoint Online with PowerShell

I’m currently spending most of my time working in Office 365, in particular SharePoint Online (along with Microsoft Flow and PowerApps). While the new modern page look is a major improvement on the classic SharePoint on-premise look, customers still want to be able to customize the default look.

To allow customisation of how lists and libraries appear, Microsoft allows you to set view formatting. This uses a JSON object to describe how elements are displayed when a row is loaded in a list view. A useful repository of open source JSON formatting samples is available at https://github.com/SharePoint/sp-dev-list-formatting.

Similarly, you can apply a JSON object to customize how a field (column) is displayed in a list view. Note, neither row or column formatting changes the data in the list item or file; it only changes how it’s displayed to users who browse the list.

While there is a lot of documentation around setting the JSON formatting using the SharePoint Online UI, there is little documentation around using PowerShell to do this. I came across this method of setting the JSON formatting object:

# Get the raw content for the JSON Definition
$listViewFormattingJSON = Get-Content -Raw -Path '.\ViewRowFormat.json';

# Update the List View Formatting Definition
$view = Get-PnPView -List $list -Identity $viewName
$view | Set-PnPView -Values @{CustomFormatter = $listViewFormattingJSON.ToString()}
Invoke-PnPQuery

And similarly, to set the column formatting:

$statusFieldFormattingJSON = Get-Content -Raw -Path '.\StatusColumnFormatting.json';
$statusField = Get-PnPField -List $ListName -Identity 'Status'
$statusField | Set-PnPField -Values @{CustomFormatter = $statusFieldFormattingJSON.ToString()}
Invoke-PnPQuery

These code snippets help to set the customized view below:

List view showing both view and column formatting

Note, I use the SharePoint Patterns and Practices (PnP) PowerShell library to provision and manage my SharePoint Online solutions.