June 30, 2022

Samir Daoudi's Technical Blog

SharePoint, Office 365, C#, .Net, SQL Server News, Tips, Ebooks, Events, Webinars ….etc

Get all SharePoint Groups using SP.JS

In this post, I will show you how you can retrieve all the SharePoint groups in a Site using SP.JS.

I needed to implement this JavaScript code to populate a bootstrap dropdown for a project which required custom development using BootStrap, SP.JS and other client side technologies.

var RootSite = "https://YourTenant.sharepoint.com/sites/YourSite/"

function Get_Groups() {
    var clientContext = new SP.ClientContext(RootSite);
    this.collGroup = clientContext.get_web().get_siteGroups();
    clientContext.executeQueryAsync(Function.createDelegate(this, this.DD_GroupsSucceeded), Function.createDelegate(this, this.DD_GroupsFailed));

function DD_GroupsSucceeded(sender, args) {
    var userInfo = '';

    var groupEnumerator = collGroup.getEnumerator();
    while (groupEnumerator.moveNext()) {
        var oGroup = groupEnumerator.get_current();
        var Group_ID=oGroup.get_id();
        var Group_Title=oGroup.get_title();
        alert (Group_ID +' - ' + Group_Title);

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


Leave a comment

You may have missed

Show Buttons
Hide Buttons

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

%d bloggers like this: