As the title suggests, this is a quick example on how to read user details from users in a SharePoint site’s group. Note that the group name must be adjusted within the code to the one you are requesting. To run this script quickly you can just place a Script Editor part on your page and wrap the code in script tags.
function retrieveAllUsersInGroup() { var clientContext = new SP.ClientContext.get_current(); var collGroup = clientContext.get_web().get_siteGroups(); var oGroup = collGroup.getByName("Mikes Group Owners"); //ADJUST THIS LINE! this.collUser = oGroup.get_users(); clientContext.load(this.collUser ); console.log("Executing query"); clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this,onQueryFailed)); } function onQuerySucceeded() { console.log("Query success"); var userInfo = ''; var userEnumerator = this.collUser.getEnumerator(); while (userEnumerator.moveNext()) { var oUser = userEnumerator.get_current(); userInfo += '\nUser: ' + oUser.get_title() + '\nID: ' + oUser.get_id() + '\nEmail: ' + oUser.get_email() + '\nLogin Name: ' + oUser.get_loginName() + "<br/></br/>"; } console.log(userInfo); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } SP.SOD.executeFunc("sp.js", null, retrieveAllUsersInGroup);
No Comments
There are no comments related to this article.
Leave a Reply