Hi,
I want to add a SP User (from AD) to a SP Group other than current user using CSOM or REST.
Below code shows how to add current user to a SP Group (Link)
var user; var visitorsGroup; function runCode() { var clientContext = new SP.ClientContext(); var groupCollection = clientContext.get_web().get_siteGroups(); // Get the visitors group, assuming its ID is 23. visitorsGroup = groupCollection.getByName('Approvers'); user = clientContext.get_web().get_currentUser(); var userCollection = visitorsGroup.get_users(); userCollection.addUser(user); clientContext.load(user); clientContext.load(visitorsGroup); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); } function onQuerySucceeded() { alert(user.get_title() + " added to group " + visitorsGroup.get_title()); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); }
But i need to add a diff user which is not current user (say domain\login).
Please help
Please remember to click 'Mark as Answer' on the post that helps you or "Vote As Helpful"