title: Trying to get List of Groups for a user using SPServices
body: <p>I came across this code and I'm trying to use it in SP 2010 Foundation. When I load the page, I get the error saying "User not found". I'm using Jquery 1.10.X and the latest SPServices version. I assume it has something to do with the "userLoginName" but I'm having trouble figuring it out. </p>
  
  <pre><code>$(document).ready(function() {
    //Populate the users pick list
    var strHTMLSiteUsers = "";
    $().SPServices({
        operation: "GetUserCollectionFromSite",
        async: false,
        completefunc: function(xData, Status) {
          $(xData.responseXML).find("User").each(function() {
            strHTMLSiteUsers += "&lt;option value='" + $(this).attr("LoginName") + "'&gt;" + $(this).attr("Name") + "&lt;/option&gt;";
          });
          $("#my_SiteUsers").append(strHTMLSiteUsers);
        }
    });
    RefreshGroupLists();
  });
  
  function RefreshGroupLists(){
    var strHTMLAvailable = "";
    var strHTMLAssigned = "";
    var arrOptionsAssigned = new Array();
    var intOpts = 0;
    var booMatch;
    var booErr = "false";
  
    $("#my_SPGroupsAssigned").html("");
    $("#my_SPGroupsAvailable").html("");
  
    if($("#my_SiteUsers").attr("value") == 0){
      alert("You must select a user");
      return;
    }
  
    //Populate the Groups Assigned
    $().SPServices({
        operation: "GetGroupCollectionFromUser",
        userLoginName: $("#my_SiteUsers").attr("value"),
        async: false,
        completefunc: function(xData, Status) {
          $(xData.responseXML).find("errorstring").each(function() {
            alert("User not found");
            booErr = "true";
            return;
          });
          $(xData.responseXML).find("Group").each(function() {
            strHTMLAvailable += "&lt;option value='" + $(this).attr("Name") + "'&gt;" + $(this).attr("Name") + "&lt;/option&gt;";
            arrOptionsAssigned[intOpts] = $(this).attr("Name");
            intOpts = intOpts + 1;
          });
          $("#my_SPGroupsAssigned").append(strHTMLAvailable);
        }
    });
  
    //Populate available site groups
    if(booErr == "false"){
      $().SPServices({
          operation: "GetGroupCollectionFromSite",
          async: false,
          completefunc: function(xData, Status) {
            $(xData.responseXML).find("Group").each(function() {
              booMatch = "false";
              for (var i=0;i&lt;=arrOptionsAssigned.length;i++){
                if($(this).attr("Name") == arrOptionsAssigned[i]){
                  booMatch = "true";
                  break;
                }
              }
              if(booMatch == "false"){
                strHTMLAssigned += "&lt;option value='" + $(this).attr("Name") + "'&gt;" + $(this).attr("Name") + "&lt;/option&gt;";
              }
            });
            $("#my_SPGroupsAvailable").append(strHTMLAssigned);
          }
      });
    }
  }
  
  function AddGroupsToUser(){
    var i;
  
    if($("#my_SiteUsers").attr("value") == 0){
      alert("You must select a user");
      return;
    }
  
    if($("#my_SPGroupsAvailable").val() == null){
      alert("You haven't selected any groups to add");
      return;
    }
    else{
      var arrGroups = $("#my_SPGroupsAvailable").val();
      for (i=0;i&lt;arrGroups.length;i++){
        $().SPServices({
            operation: "AddUserToGroup",
            groupName: arrGroups[i],
            userLoginName: $("#my_SiteUsers").attr("value"),
            async: false,
            completefunc: null
        });
      }
      RefreshGroupLists();
    }
  }
  
  function RemoveGroupsFromUser(){
    var i
  
    if($("#my_SiteUsers").attr("value") == 0){
      alert("You must select a user");
      return;
    }
  
    if($("#my_SPGroupsAssigned").val() == null){
      alert("You haven't selected any groups to remove");
      return;
    }
    else{
      var arrGroups = $("#my_SPGroupsAssigned").val();
      for (i=0;i&lt;arrGroups.length;i++){
        $().SPServices({
            operation: "RemoveUserFromGroup",
            groupName: arrGroups[i],
            userLoginName: $("#my_SiteUsers").attr("value"),
            async: false,
            completefunc: null
        });
      }
      RefreshGroupLists();
    }
  }
  </code></pre>
  
  <p>This is the <a href="http://sympmarc.com/2011/11/03/managing-sharepoint-site-user-memberships-in-multiple-groups-using-spservices/" rel="nofollow">source</a></p>