IntroductionIn this article you will see how to get all the site groups in SharePoint 2010 using ECMAScript. I have the following site groups from which I need to get the group name (Navigate to the site, click on Site Actions. Click on Site Settings. In the Users and Permissions section, click on People and Groups. In the left pane, click on Groups).Steps Involved
var groupCollection;
function getSiteGroups() {
var clientContext = new SP.ClientContext(); this.groupCollection = clientContext.get_web().get_siteGroups(); clientContext.load(groupCollection); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() { var groupName = 'Site Groups: \n'; var groupsEnumerator = this.groupCollection.getEnumerator(); while (groupsEnumerator.moveNext()) { var group = groupsEnumerator.get_current(); groupName += group.get_title() + '\n'; } alert(groupName); }
function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); }</script> <input id="btnGetSiteGroups" onclick="getSiteGroups()" type="button" value="Get Site Groups" />
ReferenceSP.Web.siteGroups Property - http://msdn.microsoft.com/en-us/library/ee554059.aspx SummaryThus in this article you have seen how to get all the site groups in SharePoint 2010 using ECMAScript.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: