Skip to main content
added 91 characters in body
Source Link
Denis Molodtsov
  • 9.8k
  • 10
  • 46
  • 96

In order to apply List Item formatting programmatically, weExport list item form footer, header and the body

$list = Get-PnPList SAMPLE_LIST-Includes ContentTypes
$contentType = $list.ContentTypes | Where-Object {$_.Name -eq "Item"}
$contentType.ClientFormCustomFormatter | Set-Content .\ClientFormCustomFormatter.json

Apply List Item formatting programmatically.

We need to to update the ClientFormCustomFormatter property for the list's content type:

Sample Contents of the ClientFormCustomFormatter.json file:

Notice headerJSONFormatter, footerJSONFormatter and bodyJSONFormatter properties:

In order to apply List Item formatting programmatically, we need to to update the ClientFormCustomFormatter property for the list's content type:

Sample Contents of the ClientFormCustomFormatter.json file:

Export list item form footer, header and the body

$list = Get-PnPList SAMPLE_LIST-Includes ContentTypes
$contentType = $list.ContentTypes | Where-Object {$_.Name -eq "Item"}
$contentType.ClientFormCustomFormatter | Set-Content .\ClientFormCustomFormatter.json

Apply List Item formatting programmatically.

We need to to update the ClientFormCustomFormatter property for the list's content type:

Sample Contents of the ClientFormCustomFormatter.json file:

Notice headerJSONFormatter, footerJSONFormatter and bodyJSONFormatter properties:

Source Link
Denis Molodtsov
  • 9.8k
  • 10
  • 46
  • 96

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"]
        }]
    }
}