Query for SharePoint Groups and Members with JQuery and SPServices

 Computer, Sharepoint, Software  Comments Off on Query for SharePoint Groups and Members with JQuery and SPServices
Dec 152015
 

The following code returns all SharePoint permissions groups and the respective members.
This uses JQuery 1.xx and SPServices.


// Add JQuery and SPServices references. //
<script type="text/javascript"  src="jquery1.11.js" ></script>
<script type="text/javascript" src="jquery.SPServices.js"></script>

<script>
// alert("Debug Check 1");
$(document).ready(function() {
// Function returns all Permissions Groups
$().SPServices({
                        operation: "GetGroupCollectionFromSite",
                        async: false,
                        completefunc: function (xData, Status) {
                                        $(xData.responseXML).find("Group").each(function() {
                                        // alert($(this).attr("Name"));
                                        getAllUsersFromGroup($(this).attr("Name"));
                                                                                           });
                                                               }
                });
 });
                             
                                                                       
// Function returns all users in respective Groups                                           
function getAllUsersFromGroup(groupName) {
// alert(groupName);
$().SPServices({
                       operation: "GetUserCollectionFromGroup",
                       groupName: groupName,
                       async: false,
                       completefunc: function (xDataUser, Status) {
                                       $(xDataUser.responseXML).find("User").each(function() {
                                       $('#GroupUsers').append("<tr><td>" + groupName + "</td><td>" + $(this).attr("Name") + "</td></tr>");
                                                                                              });
                                                                   }
                });
}
</script>

<!-- Table for Output -->
<table align="LEFT" id="GroupUsers">
<tbody>
<tr>
<tr><td>Group</td><td>Member</td></tr>
</tbody>
</table>

JQuery Sharepoint Document Library for most Recent File(s).

 Computer, Sharepoint, Software  Comments Off on JQuery Sharepoint Document Library for most Recent File(s).
Jan 112014
 

I have an email-enabled document library where reports in PDF format are delivered daily.
I need to display the most recent reports embedded on a Web Part page.
The filenames are structured as name_datestamptimestamp.pdf
Different reports are sent here so I have to discern a part of the filename (eg. LAN Utilization, WAN Utilization)

&lt;script type="text/javascript" src="/jquery-1.8.3.min.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
//alert("So Far So Good");
$(document).ready(function() {
// alert("Document is Ready");
 var soapEnv =
 "&lt;?xml version="1.0" encoding="utf-8"?&gt;  &lt;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/"&gt;  
&lt;soap:Body&gt;  
&lt;GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;  
 &lt;listName&gt;CMReports&lt;/listName&gt;  
&lt;viewFields&gt;  
&lt;ViewFields&gt; 
 &lt;FieldRef Name='LinkFilenameNoMenu' /&gt; 
 &lt;/ViewFields&gt; 
 &lt;/viewFields&gt; 
 &lt;query&gt; 
 &lt;Query&gt; 
 &lt;Where&gt; 
 &lt;Contains&gt; 
 &lt;FieldRef Name='FileLeafRef' /&gt; 
 &lt;Value Type='File'&gt;PARTOFFILENAME&lt;/Value&gt; 
 &lt;/Contains&gt; 
 &lt;/Where&gt; 
 &lt;OrderBy&gt; 
 &lt;FieldRef Name='Modified' Ascending='FALSE' /&gt; 
 &lt;/OrderBy&gt; 
 &lt;/Query&gt; 
 &lt;/query&gt; 
 &lt;rowLimit&gt;1&lt;/rowLimit&gt; 
 &lt;/GetListItems&gt; 
 &lt;/soap:Body&gt; 
 &lt;/soap:Envelope&gt;";
// alert(soapEnv);
$.ajax({
 url: "/_vti_bin/lists.asmx",
 type: "POST",
 dataType: "xml",
 data: soapEnv,
 complete: processResult,
 contentType: "text/xml; charset="utf-8""
 });
});
 function processResult(xData, Status) 
 { 
 // alert(xData.responseXML.xml);
 $(xData.responseXML).find("z\:row").each(function() {
 // alert($(this).attr("ows_LinkFilenameNoMenu"));
 var ObjHTML = "&lt;embed width='940' height='1024' src='SUBSITE/DOCUMENTLIBRARY" + $(this).attr("ows_LinkFilenameNoMenu") + "#navpanes=0' type='application/pdf'&gt;&lt;/embed&gt;";
 // $("#PDF").append(xData.responseXML.xml);
 // alert(ObjHTML);
 $("#SPDF").append(ObjHTML);
 });
 }
// ]]&gt;&lt;/script&gt;
&lt;div id="SPDF" /&gt;

I saved this snippet in an HTML file and call it from a Content Editor Web Part elsewhere.