Enable custom script on modern SharePoint sites to recover your favourite functionalities

Let me start with a HUGE disclaimer: even though it is possible to enable custom scripts on modern SharePoint, you should only consider using it when there is no other alternative.

Having custom script disabled by default on SharePoint removes functionalities that old school users miss, such as list templates and the solution gallery,among several others. Most of the features removed by custom scripts can be achieved using PnP and SharePoint Online Cmdlets.

If you need to bring back any of the functionalities listed below you will need to follow the steps described in the article below:

  1. Enable custom scripts on tenant level
  2. Enable custom script on SharePoint sites
Site feature Behavior Notes
Save Site as Template No longer available in Site Settings Users can still build sites from templates created before custom script was blocked.
Save document library as template No longer available in Library Settings Users can still build document libraries from templates created before custom script was blocked.
Solution Gallery No longer available in Site Settings Users can still use solutions created before custom script was blocked.
Theme Gallery No longer available in Site Settings Users can still use themes created before custom script was blocked.
Help Settings No longer available in Site Settings Users can still access help file collections available before custom script was blocked.
HTML Field Security No longer available in Library Settings Users can still use HTML field security that they set up before custom script was blocked.
Sandbox solutions Solution Gallery is no longer available in Site Settings Users can’t add, manage, or upgrade sandbox solutions. They can still run sandbox solutions that were deployed before custom script was blocked.
SharePoint Designer Pages that are not HTML can no longer be updated.
Handling List: Create Form and Custom Action will no longer work.
Subsites: New Subsite and Delete Site redirect to the Site Settings page in the browser.
Data Sources: Properties button is no longer available.
Users can still open data sources.
Uploading files that potentially include script The following file types can no longer be uploaded to a library
.asmx
.ascx
.aspx
.htc
.jar
.master
.swf
.xap
.xsf
Existing files in the library are not impacted.

Source

Enable custom scripts on tenant level

Before getting custom script running on your modern site, you need to make sure it is already enabled at tenant level. To verify or enable it, you should follow these steps:

  1. From your SharePoint site, click on the waffle icon
  2. Click on Admin

  3. Expand Admin centers and click on SharePoint
  4. On the SharePoint Admin Center click on Settings
  5. Scroll down and locate the Custom Script
  6. Click on Allow users to run custom script on personal sites
  7. Click on Allow users to run custom script on self-service created sites

  8. Click OK

Note: Changes to the tenant settings can take up to 24 hours to be applied.

Enable custom script on SharePoint sites

To enable custom scripts on modern sites, you will need to use SharePoint Online Cmdlets. If you don’t have it installed download it from here.

Once installed:

  1. Open the PowerShell console
  2. Execute the command
    Connect-SPOService -Url https://tenant-admin.sharepoint.com
  3. Execute the command bellow with the url for the modern site collection
    Set-SPOSite -Identity https://tenant.sharepoint.com/sites/contoso -DenyAddAndCustomizePages 0

Conclusion

Don’t enable custom scripts unless it’s your last option, having custom scripts enabled can put your tenant at risk.

A special thanks to my friends Francisca Peixoto and David Ramalho for the support over the last months to carry on with this project.


8 Responses to “Enable custom script on modern SharePoint sites to recover your favourite functionalities”

  1. Sofia Oliveira

    May 13, 2019

    Thank you for your post, it was very useful!

    So is there any other way to save sites as templates? Or without enabeling that feature I would have to create a site from scratch even though most of the sites will be used in similar projects?

    Reply
  2. Pratibha

    July 31, 2019

    Hello Joao,
    Thank you for this article.
    I have a question, I am trying to run the script in Powershell to enable SPO features, as per this article
    https://blogit.create.pt/fabiocarvalho/2017/07/28/activating-all-publishing-feature-programmatically-powershell-sharepoint-2010-2013-2016-online/ but, its come up with the error. I double-check with custom settings, it is on.
    Any advice?
    Cheers

    Reply
    • João Ferreira

      August 9, 2019

      Hi Peatibha,

      If you have the custom scripts enabled you will need to enable the Publishing feature in the correct order.
      The first feature to be enabled is the SharePoint Server Publishing Infrastructure, this is a feature you need to enable at the site collection level and it take a few minutes to get enables, is not strange to get 5 minutes or more to get the feature activated.
      The second feature to activate is the SharePoint Server Publishing at site level, this feature get enabled automatically but it requires the activation of the site collection feature first.

      If on your script you do the activation one after the other without a delay most likely it will fail.
      So after activating the first feature make sure it is really activated.

      I’m leaving here the feature IDs for your reference.

      First feature – SharePoint Server Publishing Infrastructure – f6924d36-2fa8-4f0b-b16d-06b7250180fa
      Second feature – SharePoint Server Publishing – 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb

      Reply
      • Pratibha Vinayak

        August 26, 2019

        Thank you for this reply.
        When I am trying to enable the Sie Server Publishing infrastructure feature it is coming up as Unexpected error with a correlation ID.
        Any comment?

        Reply
        • João Ferreira

          August 26, 2019

          Pratibha Vinayak,

          Custom scripts on the tenant can take up to 24 hours to get enabled across all site collections, if you just enabled the custom scripts in the admin portal that might be the cause of the issue.
          To get them enabled immediately you can create a new site collection but it will only take effect on the new site collection.

          Please try to create a new site collection and repeat the process and let me know if you get the same result.

          Have a nice day 🙂

          Reply
      • Pratibha Vinayak

        August 26, 2019

        Hi
        I run the script. It is successful for Sharepoint Server Publishing Infrastructure but not work for Sharepoint Server publishing.
        Any suggestions?

        Reply
        • João Ferreira

          August 26, 2019

          Pratibha Vinayak,

          Custom scripts on the tenant can take up to 24 hours to get enabled across all site collections, if you just enabled the custom scripts in the admin portal that might be the cause of the issue.
          To get them enabled immediately you can create a new site collection but it will only take effect on the new site collection.

          Please try to create a new site collection and repeat the process and let me know if you get the same result.

          Have a nice day 🙂

          Reply

Leave a Reply to João Ferreira


I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.

%d bloggers like this: