.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Retrieving all users from all SharePoint groups of a site collection using ECMA script

Posted By:Makarand Kulkarni       Posted Date: May 12, 2014    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

This article explains how to retrieve all users from all SharePoint groups using ECMA script.

With the use of ECMA Script we can add/edit/delete or manipulate SharePoint data. We are going to see how to get all users from SharePoint groups in following article:

//declare site url first,
var siteUrl = '/sites/MySiteCollection';

then write the following lines of code,

ExecuteOrDelayUntilScriptLoaded(getUserInfo, 'SP.js');

function getUserInfo()
  var clientContext = new SP.clientContext(siteUrl);
  this.collGroup = clientContext.get_web().get_siteGroups();
  client.load(collGroup, 'Include(Users)');
  clientContext.executeQueryAsync(Function.createDelegate(this, this.OnSucceeded), Function.createDelegate(this, this.OnFailed));

on sucess of the above code 'OnSucceeded' function will get executed. Otherwise 'OnFailed' function will get executed.

function OnSucceeded()
 var userInfo = "";
 var groupEnum = collGroup.getEnumerator();
   var groupObj = groupEnum.getCurrent();
   var userCollection = groupObj.get_users();
   var userEnum = userCollection.getEnumerator();
      var userObj = userEnum.get_current();
      this.userInfo += '\n GroupID: '+ groupObj.get_id()
                       + '\n Group Title: ' + groupObj.get_title()
                       + '\n User: ' + userObj.get_loginName();

function OnFailed(sender, args);
  alert('Request failed. ' + args.get_message() + '\n args.get_stackTrace()');

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend