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.

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.

1
2
3
4
var web = ctx.get_web();
var meGroups = web.get_associatedMemberGroup();
ctx.load(web);
ctx.load(meGroups);

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.
1
web.set_membersCanShare(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.
1
meGroups.set_allowMembersEditMembership(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(‘’).
1
web.set_requestAccessEmail('');

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.

Hope you like it and find it helpful.

Share
© 2024 Darius 231 All Rights Reserved.
Theme by hiero