0

I want to check the current user exisit in a AD group inside the SharePoint Group using SPServices JQuery. I used the below code snippet but not successed. Any suggestions?

$().SPServices({
        operation: "GetGroupCollectionFromUser",
        userLoginName: $().SPServices.SPGetCurrentUser(),
        async: false,
        completefunc: function (xData, Status) {

            if ($(xData.responseXML).find("Group[Name='SP Group Name']").length == 1) 
            {

             }
            else 
            {

            }
        }

    });
  • What failed? The call or the result you were expecting? – Eric Alexander May 29 '15 at 14:09
  • In the given code, I can able to check only SP group. Any code snippet to check AD group will helpful !! – Suresh Kumar May 29 '15 at 14:19
1

Sorry I wasn't reading your question clearly. The above script works if the user is explictly defined. However, there is no method in SPServices that expands group membership based on AD groups. You'll likely need server side code for that.

0

There actually is a way!

Create a group in Sharepoint and add the AD group to the Sharepoint group.

Then you can use spservices to test for membership in the Sharepoint group.

I've been doing this and it works just right! My code for this is essentially the same as yours:

//return true if current user belongs to Sharepoint Group
function isMemberofSharepointGroup(whatgroup){
    var ismember;
   $().SPServices({
     operation: "GetGroupCollectionFromUser",
     userLoginName: $().SPServices.SPGetCurrentUser(),
     async: false,
     completefunc: function(xData, Status) {
        //var $groups = $(xData.responseXML).find("Group[Name^='" + whatgroup + "']");   
        if($(xData.responseXML).find("Group[Name='" + whatgroup + "']").length == 1){
            ismember = true;
        }else{
            ismember = false;
        }
      }
   });
    return ismember;
}

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.