2

I created a SharePoint Hosted Add-In for SharePoint Online, which injects a JavaScript File to the Masterpage through a custom action.

https://channel9.msdn.com/Blogs/Office-365-Dev/JavaScript-injection-in-SharePoint-Online-Office-365-Developer-Patterns-and-Practices

It works fine on any WSC like:

Only on: https://mysite.sharepoint.com

I am getting a permission error. Access denied.

Even on a fresh Office 365 trial Account, is there something special with this "root" WSC?

0

This could be due to the setting within SharePoint that is set by default to block scripts from running, which causes Access Denied errors when trying to add Custom Actions using ScriptLink as the location. I followed the same sample as you did and received the same Access Denied error. The good news is that this can be set to Allow, which fixed it for me. You can go into your Office 365 account, then Admin, then Sharepoint Admin. Go to Settings and find the section called Custom Script and choose Allow users to run custom script on self-service created sites. You can allow it for Personal Sites too if you want.

However, this change can take up to 24 hours, and I wanted to test it right away. So I referenced this page and I ran the following commands via SP PowerShell:

Connect-SPOService

You should see the following output:

cmdlet Connect-SPOService at command pipeline position 1
Supply values for the following parameters:
Url:

Input your admin url for your sharepoint site, so if your site is https://mysite.sharepoint.com then you would type https://mysite-admin.sharepoint.com It will then prompt you to login. After you login, it should take you back to the PS prompt. Now use the following command:

Set-SPOsite "https://mysite.sharepoint.com" -DenyAddAndCustomizePages 0

It took 10 seconds or a little more for me for it to make the change. Then I tried my code again and it worked! I hope it does for you too!

| improve this answer | |

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.