Link to home
Start Free TrialLog in
Avatar of Fredd
Fredd

asked on

SharePoint - JS to access Permission Groups

Sharepoint 2013 onprem, FC only

I need to get users in a permission group and also add/delete users in a group.
I'm using the code from
https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/hh185012(v%3Doffice.14)
However, I'm getting "typeerror: B is undefined" which is deep in the create delegate function and I can cipher what the problem is.

Anyone have any luck with using JS to get and edit names in a sharepoint group?
Avatar of Piotr Strycharz
Piotr Strycharz
Flag of Poland image

You may simplify the code from the given page, especially createDelegate method which you have problem with. The code is:

var clientContext = new SP.ClientContext.get_current()
var collGroup = clientContext.get_web().get_siteGroups();
var oGroup = collGroup.getById(111)
var userCreationInfo = new SP.UserCreationInformation();
userCreationInfo.set_loginName('DOMAIN\\alias');
this.oUser = oGroup.get_users().add(userCreationInfo);
clientContext.load(oUser);
clientContext.executeQueryAsync(
  function() { console.log('OK') },
  function(sender, args) { console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()) }
);

Open in new window


Note that there is no need to supply url, email and user name. Ensure double backslash in user login. Also - switch your SharePoint to debug mode: in web.config find <compilation batch="false" debug="false"> node and change it to <compilation batch="false" debug="true">. Perhaps it will produce more readable error messages.
Avatar of Fredd
Fredd

ASKER

Thanks - I only have FC - not farm access
Regardless, I need code to add and delete a user from a group -
is it simply    .delete.(userCreationInfo).

also have you actually run this successfully ?
Where is this kind of interface documented (for example, to see all users of a group).  thanks
ASKER CERTIFIED SOLUTION
Avatar of Piotr Strycharz
Piotr Strycharz
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial