Issue
On a SharePoint Online site, we have created a Team site collection. Since we need to do a small POC and use the Content Editor WebPart (CEWP), we edit the page and click Add WebPart option. I wondered what would happen since there were only few WebParts to be added, as shown below.
Figure 1: No CEWP
Also, there were no search related Web parts and it seems to be missing other categories as well. My first thought was activating the publishing feature. Hence, I went and activated both the publishing features Site level and Web level but found no luck.
Solution- After searching on Google, I found that this issue is related to a new feature in SharePoint Online called Custom Script. This feature enables or disables the scripting capabilities on the site.
Options from UI for enabling and disabling this feature are available on SharePoint admin center site, as shown below.
Figure 2: SharePoint admin site - option to enable or disable the custom scripting
If we do the setting from SharePoint admin center site, this setting is applied to all the site collections available in the tenant but if on some sites, we don’t want this feature, then we can do this setting on site collection level also.
Also, if we do this setting from SharePoint admin center site, it takes around 24 hrs. to take the effect.
To have an immediate effect, we need to apply the setting at site collection level. At site collection level, we can apply setting, using PowerShell command.
Set-SPOsite is a PowerShell command, which we need to use to set the setting.
Steps to enable the Custom Script feature at site collection level, using PowerShell command:
- Open the “SharePoint Online Management Shell” and run it as an administrator.
- Connect to Office 365, using PowerShell command “Connect-SPOService” as
Connect-SPOService -Url https://prasham1-admin.sharepoint.com <SharePoint admin center URL>
This command will prompt for the credentials, as given below.
Figure 3: SharePoint Online Management Shell - Credential prompt for connecting to Office 365
- Once the credentials are entered, we are ready to run our next command Set-SPOsite as
Set-SPOSite <Site Collection URL for which we need to change the setting> -DenyAddAndCustomizePages 0 (“DenyAddAndCustomizePages” set to Zero means enabling the custom scripting on the given site collection.)
Thus, we used given PowerShell command. We applied the setting for our site collection. We refreshed the page and again tried to add CEWP and we can see the CEWP as well other WebParts also, as given below.
Figure 4: Adding CEWP on page after enabling custom script feature at our site collection level
Not only CEWP but other WebParts like Script Editor, Silverlight Web Part in category “Media and Content” are also visible. WebParts from other categories like Business Data, Content Rollup and Search are also visible.
There are more other features also, which are affected because of Custom Scripts feature. Kindly refer https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f?ui=en-US&rs=en-US&ad=US , in this article its very detailed explained all the features which are affected.
Thanks.
Enjoy reading.
As usual any comments/ suggestions/ feedback/ questions are always welcome.