GetUserMemberships need help..

Dec 2, 2010 at 6:12 PM
Edited Dec 2, 2010 at 6:15 PM

I'm trying to grab the "DisplayName" childnode of "MembershipData" (using something like this)

$().SPServices({
     operation: "GetUserMemberships",
     async: false,
     completefunc: function(xData, Status) {
       $(xData.responseXML).find("MembershipData").each(function() {
      			displayname = $(this).find("DisplayName").text;<-- not sure how to word this?
     	});
     }
   });


Result of (xData.responseXML.xml) is as below:
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetUserMembershipsResponse xmlns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService">

      <GetUserMembershipsResult>
        <MembershipData>
          <Source>SharePointSite</Source>
          <MemberGroup>
            <SourceInternal>
            8bb1220f-de8b-4771-ac3a-0551242cf2bd</SourceInternal>
            <SourceReference>
            9E296574-2783-4DD1-9BDE-8F16D43641D7</SourceReference>
          </MemberGroup>
          <Group>SharePoint Sites</Group>
          <DisplayName>IT Blog</DisplayName>
          <Privacy>Public</Privacy>
          <MailNickname>nickname</MailNickname>
          <Url>
          http://intranet.com:80/collaboration/IT/Blog</Url>
          <ID>53</ID>
          <MemberGroupID>7</MemberGroupID>
        </MembershipData>
        <MembershipData>
          <Source>SharePointSite</Source>
          <MemberGroup>
            <SourceInternal>
            8bb1220f-de8b-4771-ac3a-0551242cf2bd</SourceInternal>
            <SourceReference>
            8A45CDB5-1A42-4B02-8FD2-87B6BFB27270</SourceReference>
          </MemberGroup>
          <Group>SharePoint Sites</Group>
          <DisplayName>IT Collaboration
          Site</DisplayName>
          <Privacy>Public</Privacy>
          <MailNickname>nickname</MailNickname>
          <Url>
          http://intranet.com:80/collaboration/IT</Url>
          <ID>31</ID>
          <MemberGroupID>6</MemberGroupID>
        </MembershipData>
        <MembershipData>
          <Source>SharePointSite</Source>
          <MemberGroup>
            <SourceInternal>
            8bb1220f-de8b-4771-ac3a-0551242cf2bd</SourceInternal>
            <SourceReference>
            A969AF31-CB52-4725-B3F8-3BF843E63E8C</SourceReference>
          </MemberGroup>
          <Group>SharePoint Sites</Group>
          <DisplayName>Chris Centeno Blog</DisplayName>
          <Privacy>Public</Privacy>
          <MailNickname>nickname</MailNickname>
          <Url>
          http://intranet.com:80/collaboration/IT/Chris_Blog</Url>
          <ID>75</ID>
          <MemberGroupID>8</MemberGroupID>
        </MembershipData>
        <MembershipData>
          <Source>SharePointSite</Source>
          <MemberGroup>
            <SourceInternal>
            8bb1220f-de8b-4771-ac3a-0551242cf2bd</SourceInternal>
            <SourceReference>
            2E97EDDE-C577-4531-A7DB-0132549454F8</SourceReference>
          </MemberGroup>
          <Group>SharePoint Sites</Group>
          <DisplayName>Information Technology</DisplayName>
          <Privacy>Public</Privacy>
          <MailNickname>nickname</MailNickname>
          <Url>http://intranet.com:80/IT</Url>
          <ID>175</ID>
          <MemberGroupID>26</MemberGroupID>
        </MembershipData>
      </GetUserMembershipsResult>
    </GetUserMembershipsResponse>
  </soap:Body>
</soap:Envelope>


 

Dec 2, 2010 at 7:43 PM
Edited Dec 2, 2010 at 7:57 PM

Hi,

First you can grab the contents in xml:
var x = $("<xml>" + $(this).text() + "</xml>");

Then you can traverse the xml content to get the item you want, e.g.:
x.find("MembershipData").each(function() {
  displayname= $("DisplayName", $(this)).text();
});

I didn't try this out, but I think this will help you.

Best regards, Anita

Dec 3, 2010 at 1:01 PM
Edited Dec 3, 2010 at 1:01 PM

Super this worked!! THANKS!!

Dec 4, 2010 at 1:50 PM

Glad I could help.