0

This question is from a site-developer perspective not from a sysadmin perspective. Site Developers don't have access to the SP server itself, they are users with "full control" permissions via browser.

We have started doing some custom formatting of list views using JSON for column formats as well as for view formats. Unfortunately, with the built-in JSON editor, we are always one "switch to design mode" click away from one of the developers wiping away all JSON progress. There is also no configuration control or versioning.

Our current workflow is for the developers to edit the JSON in some third-party editor (Notepad++ or similar) and then copy and paste the JSON to the built-in JSON editor.

Is there a better way of doing this?

2
  • Sadly, there is no built in way to preserve JSON-formatting or version control. Commented Feb 8 at 9:03
  • @Christoffer - that was what I was afraid of. JSON formatting seems like such a throwback to the early days of the web. Handcoding HTML and CSS, no version control, anything goes.
    – Carlos N
    Commented Feb 8 at 15:41

1 Answer 1

1

Unfortunately, there is no SharePoint out of the box feature for backup/versioning of SharePoint JSON formatting.

However, if you want to backup the JSON formatting codes locally, you can do it using the PnP PowerShell.

Below is the sample script which backups the column, view and form formatting JSON in SharePoint site. This script is directly taken from the script sample at (Thanks to Dan Toft): Extract all custom formatting

function get-customFormatting() {
    $url = Read-Host -Prompt "Enter the URL of the site you wish to backup custom formatting from"
    Connect-PnPOnline $url -Interactive

    try {
        $web = Get-PnPWeb -Includes Title
    }
    catch {
        Write-Host "Please connect to a site first" -Color Red
        return;
    }

    Write-Host "Backing up formatting for '$($web.Title)', fetching lists";

    $lists = Get-PnPList -Includes Id, Title, Views, Fields, ContentTypes | Where-Object { -not $_.Hidden }

    Write-Host "Fetched data - starting backup";


    foreach ($list in $lists) {
        $fields = $list.Fields | Where-Object { $_.CustomFormatter -ne $null -and $_.CustomFormatter -ne "" }
    
        foreach ($field in $fields) {
            try {
                Write-Host "List '$($list.Title)' > field: '$($field.Title)'";
                New-Item -Path "CustomFormatting\$($list.Title)\Columns\" -Name "$($field.Title) ($($field.InternalName)).column-formatter.json" -ItemType File -Value $($field.CustomFormatter | ConvertFrom-Json | ConvertTo-Json -Depth 100) -Force | Out-Null;
            }
            catch {
                Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red;
            }
        }

        $views = $list.Views | Where-Object { $_.CustomFormatter -ne $null -and $_.CustomFormatter -ne "" }
        foreach ($view in $views) {
            try {
                Write-Host "List '$($list.Title)' > `View: '$($view.Title)'";
                New-Item -Path "CustomFormatting\$($list.Title)\Views\" -Name "$($view.Title).view-formatter.json" -ItemType File -Value $($view.CustomFormatter | ConvertFrom-Json | ConvertTo-Json -Depth 100) -Force | Out-Null;
            }
            catch {
                Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red;
            }
        }

        $formCustomizer = $list.ContentTypes | Where-Object { $_.ClientFormCustomFormatter -ne $null -and $_.ClientFormCustomFormatter -ne "" }
        foreach ($form in $formCustomizer) {
            try {
                Write-Host "List '$($list.Title)' > form: '$($form.Name)'";
                New-Item -Path "CustomFormatting\$($list.Title)\Forms\" -Name "$($form.Name).form-formatter.json" -ItemType File -Value $($form.ClientFormCustomFormatter | ConvertFrom-Json | ConvertTo-Json -Depth 100) -Force | Out-Null;
            }
            catch {
                Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red;
            }
        }
    }

}

get-customFormatting;
2
  • Can this script be run by a non-admin through the web browser, or does it need to be run at the server?
    – Carlos N
    Commented Feb 8 at 15:38
  • 1
    I know site owners (with full control permissions) can run the script from their system (laptop/desktop) after installing PnP PowerShell. You can try running the script with Edit/Read permissions once to confirm at your end. Commented Feb 8 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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