0

Suppose we created a list with a custom list form layout. Now, I want to move this list to a different SharePoint tenant/site. How do I programmatically apply the custom form laout?

enter image description here

More details I am using SharePoint PnP Provisioning templates to export and import lists. Unfortunately, it does not seem that the PnP Provisining template contains list item form's laoyout.

Example of the Header JSON that I am trying to deploy programmatically:

{
    "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": "36px"
                    }
                }
            ]
        },
        {
            "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]"
                }
            ]
        }
    ]
}

Is there a way to apply these JSON customizations using PowerShell PnP?

5
  • The New feature of custom list templates might help you Jul 24 '21 at 2:31
  • Thank you Ganesh. Is there a way to deploy JSON formatting for list items? I am trying to move it from tenant to tenant. Jul 24 '21 at 5:48
  • You are asking about list form JSON configuration, right? Or column/view formatting? Jul 24 '21 at 9:49
  • Yes, I am asking about the list item form customizations. Header, body and footer. See the screenshot for an example. Jul 24 '21 at 13:25
  • I have been busy this weekend, but I think you already got it. We need to extract the JSON from content type property ClientFormCustomFormatter. Jul 25 '21 at 10:02
0

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:

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:

Notice headerJSONFormatter, footerJSONFormatter and bodyJSONFormatter properties:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.