Using jQuery to return all members / users of a group #in #SP2010 #SharePoint
I’ve recently had cause to determine if a user is within a particular group in SharePoint and act upon the output.
Luckily the standard SharePoint web services allow to query for this information utilising the User Group service at location: http://<server>/_vti_bin/usergroup.asmx.
In particular the method GetUserCollectionFromGroup will provide the complete list including the Windows SAMAccountName (login name) as part of the return.
However, in this instance I was caught a little by a permissions problem. Although I could query the web service, it kept returning a status of “parsererror” and an output of “Access Denied”.
This was resolved by changing the group settings to allow “Everyone” to read the membership of the group.
Code Example
The following code utilises jQuery to access the web service:
1 <script type='text/javascript'> 2 3 _spBodyOnLoadFunctionNames.push("getUserCollectionFromGroup"); 4 5 function getUserCollectionFromGroup() { 6 var soapEnv = 7 "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \ 8 <soap:Body> \ 9 <GetUserCollectionFromGroup xmlns='http://schemas.microsoft.com/sharepoint/soap/directory/'> \ 10 <groupName>Group Name Here</groupName> \ 11 </GetUserCollectionFromGroup> \ 12 </soap:Body> \ 13 </soap:Envelope>"; 14 $.ajax({ 15 url: "/_vti_bin/usergroup.asmx", 16 type: "POST", 17 dataType: "xml", 18 data: soapEnv, 19 complete: getUserCollectionFromGroupReturn, 20 contentType: "text/xml; charset=\"utf-8\"" 21 }); 22 } 23 function getUserCollectionFromGroupReturn(xData, status) { 24 alert("Status: " + status); 25 alert("Output: " + xData.responseText); 26 } 27 </script> 28
Leave a Reply Cancel reply
Tags
Top Posts
- Calculated Column Formula: Probability and impact analysis for risks #SharePoint #SP2010 #ProjectServer #PS2010 #EPM #MSProject #in
- Excel formulas not auto calculating but F9 still works #in
- Change the default PWA site URL in Project Home for #ProjectOnline #Office365 #PPM #PMOT #PMO #MSProject
- Splitting a date into Year, Quarter and Month for analysis purposes in InfoPath 2010 #SP2010 #SharePoint #in
- Sharepoint 2013 “mark task complete”
- Export Lists Schema to XML using CSOM and PnP
- #SharePoint Web Front-End HTTP 404 Response but no errors in the log #SP2010 #PS2010 #MSProject #ProjectServer #in
- Automating SharePoint 2013 Usage Reports
- Writing History events from a SharePoint designer Workflow
- #Project Roadmap #CDS #App Overview #PPM #ProjectManagement #MSProject #ProjectOnline #Office365 #PowerPlatform #Dynamics365 #PowerBI Part 3
Blogroll
Archives
Blog Stats
- 570,547 hits
Thanks buddy… You taught me how to use JQuery in sharepoint.