SharePoint Online: How to handle script editor webpart
Today in this article, we will learn about how to work with script editor web part in SharePoint online.
Introduction
We have found that there are problem in the script editor web part in SharePoint online - we cannot find the script editor web part in SharePoint online site. After some analysis we got to know that in SharePoint online site script editor web part is not available by default. In order to make it available we need to enable the custom script from SharePoint Tenant admin center. Here, in this article we will learn how to enable this.
Verify that script editor web part is not available by default:
Navigate to the edit your web part page – > Insert -> Web Part -> Categories ->Media and Content
Here we can see that “Script Editor” web part is missing. Not only that we can not see also “Content Editor” web part and many more. Please see the below screen shot:
Now go to your tenant setting page thru this url
https://sprnd-admin.sharepoint.com/\_layouts/15/online/TenantSettings.aspx
Note: Here “sprnd” is the test tenant name, you need to pass your tenant name.
Now see the “Custom Script” section by default both the radio button are selected as prevent – this is the default behavior and due to this script editor and content editor web part is missing from SharePoint online page.
- Prevent users from running custom script on personal sites.
- Prevent users from running custom script on self-service created sites)
Now select to allow users to run custom script for both the radio button as like below:
- Allow users from running custom script on personal sites.
- Allow users from running custom script on self-service created sites)
Now click on the ok button and once you save it , this may take 24 hours to reflect the changes – this is what the message says from Microsoft but this was not correct at least for us. We had waited for around 3 days but still didn’t see the script editor web part in my page.
Then what to do?
Enable script editor webpart using CSOM PowerShell To overcome this issue run the below PowerShell script – this will immediately add the script editor and content editor web part in the web part category. This is the reason to write and share this article.
1.$adminUserID=”youradminaccount@< sprnd.onmicrosoft.com >”
2.$userCredential = Get-Credential -UserName $adminUserID -Message “Enter password”
3.Connect-SPOService -Url https://sprnd-admin.sharepoint.com/ Jump -Credential $userCredential
4.Set-SPOsite “https://sprnd.sharepoint.com/sites/TestSite001 Jump ″ -DenyAddAndCustomizePages 0
Notes:
- It should be your tenant domain account and your actual site.
- Here we have used the test trial tenant site.
- In Connect-SPOService pass your tenant admin url
- In Set-SPOsite pass the site url where you want to add the script editor web part.
- If your tenant admin account has MFA (multi factor authentication) enabled , we cannot execute this – to execute this script use the account which does not have MFA enabled.
Verify that script editor web part is available after executing the PowerShell Script:
After executing the above script – immediately come to the same page – wow we can see the script editor, content editor and many other web parts those were not there before the script execution under “Categories”:
Why Microsoft does not allow to add the script editor web part by default?
Considering the up most security – Microsoft does not recommend to add the custom script into the page. If we want to add any custom scripting in to our SharePoint online page – we need to add these out thru the SPFx framework.
Summary: What we had here?
Hence, in this article, we have learned how to enable script editor web part in SharePoint Online and work with.
References
See Also
- Security considerations of allowing custom script
- Getting started with SharePoint Online Management Shell