3

I tried this code, but I get only the SharePoint Groups.

var groupCollection;

function getAllGroups() {
    var ctx = new SP.ClientContext();
    groupCollection = ctx.get_web().get_siteGroups();
    ctx.load(groupCollection);
    ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFailure));
}

function onSuccess() {
    var grpColEnum = groupCollection.getEnumerator();
    var ulcollection = document.getElementById('ulGroup');
    while (grpColEnum.moveNext())
    {
        var currentGrp = grpColEnum.get_current();
        ulcollection.innerHTML += '<li>' + currentGrp.get_id() + ':' + currentGrp.get_title() + '</li>';
    }

}

function onFailure(sender, args) {
    alert('Failed:' + args.get_message() + '\n' + args.get_stackTrace());
}

Please do needful to get "Active Directory" groups and group members.

  • The code you are using is to get the collection of groups for the site collection – Yayati Jul 23 '15 at 13:48
  • Then how to get "Active Directory" groups? – SNGOKUL Jul 23 '15 at 13:51
  • Don't know how helpful it will be, but check out my question: sharepoint.stackexchange.com/questions/62606/… – Muhammedh Jul 23 '15 at 13:53
  • Here is another link with same type of question. Hope if you can get help from it. sharepoint.stackexchange.com/questions/95059/… – Yayati Jul 23 '15 at 14:00
  • Actually you show me is a C# coding but i should work on CSOM using JavaScript so please let me show CSOM code or links. – SNGOKUL Jul 23 '15 at 14:45
2

You can get AD users and groups that have already been ensured in SharePoint. That means users that have at least once logged in to the site, or have been resolved in user picker.

There is no API to query AD through SharePoint and no way to resolve users from AD group.

Active Directory groups appear in SharePoint as users (so you cannot get members). SharePoint groups, users, AD groups are all principals in JSOM. You can check type of principal using get_principalType() method.

Sample code:

var context = SP.ClientContext.get_current()
var web = context.get_web()
var user = web.getUserById(1)
context.load(user)
context.executeQueryAsync(..., ...)

//rest executed in success callback
user.get_principalType()

Some of the possible results:

  • 1 - user
  • 4 - AD group
  • 8 - SharePoint group

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.