Changing the Access Requests Settings of a SharePoint Online site with JavaScript (JSOM)

Recently I got a requirement from a client that wanted to be able to modify the Access Requests Settings of a SharePoint online site to:

  • Prevent users from Sharing the site and individual files and folders.
  • Prevent users from inviting others to the site members group.
  • Prevent non authorized users from sending access requests.

Changing the Access Requests Settings of a SharePoint Online site with JavaScript1

This needed to be done with the JavaScript Object Model and the code I used to meet this requirement is the following.

I had to split the logic into two requests. On the first request, I obtained the web and the group of users who had been given contribute permissions to the Web site.

On the second request, I set the configurations over the web and groups objects:

  • Prevent users from Sharing the site and individual files and folders by setting the Members Can Share property of the current web to false.
  • Prevent non authorized users from sending access requests by setting the Allow Members Edit Membership property of the groups given contribute permission to false.
  • Prevent users from inviting others to the site members group by setting the Request Access Email property of the current web to string empty(”).

Finally, after executing the script within the site and opening the Access Requests Settings modal windows, you can see that all of the options are now unchecked.

Changing the Access Requests Settings of a SharePoint Online site with JavaScript2

Hope you like it and find it helpful.