In order to apply List Item formatting programmatically, we need to to update the ClientFormCustomFormatter
property for the list's content type:
Connect-PnPOnline -UseWebLogin -Url https://contoso.sharepoint.com/sites/SampleSite
$list = Get-PnPList SAMPLE_LIST_TITLE -Includes ContentTypes
$contentType = $list.ContentTypes | Where-Object {$_.Name -eq "Item"}
$json = Get-Content .\ClientFormCustomFormatter.json
$contentType.ClientFormCustomFormatter = $json
$contentType.Update($false)
$contentType.Context.ExecuteQuery();
Sample Contents of the ClientFormCustomFormatter.json
file:
{
"headerJSONFormatter": {
"elmType": "div",
"attributes": {
"class": "ms-borderColor-neutralTertiary"
},
"style": {
"width": "99%",
"border-top-width": "0px",
"border-bottom-width": "1px",
"border-left-width": "0px",
"border-right-width": "0px",
"border-style": "solid",
"margin-bottom": "16px"
},
"children": [{
"elmType": "div",
"style": {
"display": "flex",
"box-sizing": "border-box",
"align-items": "center"
},
"children": [{
"elmType": "div",
"attributes": {
"iconName": "Mail",
"class": "ms-fontSize-42 ms-fontWeight-regular ms-fontColor-themePrimary",
"title": "Details"
},
"style": {
"flex": "none",
"padding": "0px",
"padding-left": "0px",
"height": "35px"
}
}]
}, {
"elmType": "div",
"attributes": {
"class": "ms-fontColor-neutralSecondary ms-fontWeight-bold ms-fontSize-24"
},
"style": {
"box-sizing": "border-box",
"width": "100%",
"text-align": "left",
"padding": "21px 12px",
"overflow": "hidden"
},
"children": [{
"elmType": "div",
"txtContent": "=' ' + [$Title]"
}]
}]
},
"footerJSONFormatter": "",
"bodyJSONFormatter": {
"sections": [{
"displayname": "",
"fields": ["Subject", "Sent", "Importance"]
}, {
"displayname": "",
"fields": ["From", "To", "CC"]
}, {
"displayname": "",
"fields": ["Body", "Archive ID"]
}]
}
}