Saturday 3 September 2011

Get all Groups Javascript\Ecmascript Client object model sharepoint 2010


An example of how to get all the Groups in a site collection i.e. SiteGroups using ECMAScript\Javascript Client Object model.

<script type="text/javascript">

var currentcontext = null;
var currentweb = null;

ExecuteOrDelayUntilScriptLoaded(GetGroups, "sp.js");

function IteratethroughGroup()
{
currentcontext = new SP.ClientContext.get_current();

currentweb = currentcontext.get_web();

this.groupCollection = currentweb.get_siteGroups();

currentcontext.load(this.groupCollection);

currentcontext.executeQueryAsync(Function.createDelegate(this, this.ExecuteOnSuccess),
Function.createDelegate(this, this.ExecuteOnFailure));

}


function ExecuteOnSuccess(sender, args) {

var listEnumerator = this.groupCollection.getEnumerator();

while (listEnumerator.moveNext()) {
var item = listEnumerator.get_current();

groupName = item.get_title();

alert(groupName);
}
}

function ExecuteOnFailure(sender, args) {
alert("error");
}
</script>

Related : Get current user's group Ecmascript\Javascript Client Object model SharePoint 2010

Ads by Google

1 comment: