GET All Sub Sites and Users Info and Lists Info Using Javascript with console window
tested in sharepoint 2007 , 2010 & 2013
console.clear();
var jQueryScriptOutputted = false;
function initJQuery() {
if (typeof(jQuery) == 'undefined') {
if (! jQueryScriptOutputted) {
jQueryScriptOutputted = true;
var path = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js";
var sppath = "http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js";
var script = document.createElement( 'script' );
script.src = path;
document.getElementsByTagName( 'head' )[0].appendChild( script );
var spservice = document.createElement('script');
spservice.src= sppath;
document.getElementsByTagName( 'head' )[0].appendChild( spservice );
}
setTimeout("initJQuery()", 100);
}
else {
$(function() { ExecuteRequiredScript(); });
}
}
initJQuery();
var AllLists = "";
function ExecuteRequiredScript(){
GetAllSubWebs();
}
function GetAllSubWebs(){
var count = 0;
console.clear();
$().SPServices({
operation:"GetWebCollection",//GetWebCollection,GetAllSubWebCollection
async: false,
completefunc: function (xData, status) {
console.log(status);
$(xData.responseXML).find("Web").each(function() {
count++;
var title = $(this).attr("Title");
var url = $(this).attr("Url");
console.log(title +"\t" +url );
if(url.indexOf("current weburl") > -1){
getOwnersgrpNAme(title,url);
getUsers(title,url);
}
});
//console.log( AllLists);
console.log(" Sub Webs count \t"+count);
}
});
}
function getCurrentUserRoleforUser(username,url) {//alert(username);
var rolename="";
var counter=0;
$().SPServices({
operation: "GetRoleCollectionFromUser",
userLoginName:username,
webURL:url,
async: false,
completefunc: function (xData, Status) {
if( Status == "success") {
$(xData.responseXML).find("Role").each(function () {
if(counter==0)
{
rolename=$(this).attr("Name");
counter++;
}
else
{
rolename+=";"+$(this).attr("Name");
}
});
}
}
});
return rolename;
}
function getCurrentUserRole(group,url) {
var rolename="";
var counter=0;
$().SPServices({
operation: "GetRoleCollectionFromGroup",
groupName:group,
webURL:url,
async: false,
completefunc: function (xData, Status) {
if( Status == "success") {
$(xData.responseXML).find("Role").each(function () {
if(counter==0)
{
rolename=$(this).attr("Name");
counter++;
}
else
{
rolename+=";"+$(this).attr("Name");
}
});
}
}
});
return rolename;
}
function getUsers(title,url)
{
var perms="";
$().SPServices({
operation: "GetUserCollectionFromWeb",
webURL: url,
async: false,
completefunc: function (xData, Status) {
$(xData.responseXML).find("User").each(function() {
var liHtml = $(this).attr("Name");
perms=getCurrentUserRoleforUser($(this).attr("LoginName"),url);
AllLists += title+"\t"+url+"\t"+perms+"\t"+liHtml+"\t"+"\n";
});
console.log( AllLists);
}
});
}
function getOwnersgrpNAme(title,url){
console.log("Getting Owners");
var siteusers="",rolename="";
$().SPServices({
operation: "GetGroupCollectionFromWeb",
webURL:url,
async: false,
completefunc: function(xData, Status) {
//var AllLists = "";
$(xData.responseXML).find("Group").each(function () {
var name = $(this).attr("Name");
rolename=getCurrentUserRole(name,url);
siteusers=getGroupOwners(title,url,name);
AllLists += title+"\t"+url+"\t"+rolename+"\t"+name+"\t"+siteusers+"\n";
});
console.log( "successuser1");
}
});
//return siteowner;
}
function getGroupOwners(title,url,groupName) {
var ownerdata = "";
// Gets users within Owners group
$().SPServices({
operation: "GetUserCollectionFromGroup",
groupName: groupName,
webURL:url,
async: false,
completefunc: function (xData, Status) {
//alert(groupName+" "+Status);
$(xData.responseXML).find("User").each(function () {
var displayName = $(this).attr("Name");
if(ownerdata ==""){
ownerdata =displayName ;
}
else{
ownerdata =ownerdata +";"+displayName ;
}
});
}
});
return ownerdata;
}
function GetAllListsIntheSite(wburl,title,siteOwners){
$().SPServices({
operation: "GetListCollection",
webURL:wburl,
async: false,
completefunc: function( xData, Status ) {
var AllLists = "",AllLibraries = "",UngroupedLists = "";
$( xData.responseXML ).find("Lists > List").each(function() {
var $node = $(this);
var ListTitle = $node.attr("Title");
var ListDefaultviewUrl = $node.attr("DefaultViewUrl");
var modified = $node.attr("Modified");
var modifiedstr=modified.substr(4,2)+"/"+modified.substr(6,2)+"/"+modified.substr(0,4)+" "+modified.substr(9,2)+":"+modified.substr(12,2);
if(ListDefaultviewUrl.indexOf("/_catalogs/")== -1){
if(ListDefaultviewUrl.indexOf("/Lists/") > 0){
var itemCount=GetItemCount(ListTitle,wburl);
AllLists += ListTitle+"\t , \t"+"List"+"\t , \t"+ListDefaultviewUrl+"\t , \t"+title+"\t , \t"+wburl+"\t , \t"+siteOwners+"\t , \t"+modifiedstr+"\t , \t"+ itemCount +" Items"+"\n";
}
else if(ListDefaultviewUrl.indexOf("/Forms/") > 0){
AllLibraries +=ListTitle+"\t , \t"+"Document Library"+"\t , \t"+ListDefaultviewUrl+"\t , \t"+ title+"\t , \t"+wburl+"\t , \t"+siteOwners+"\t , \t"+modifiedstr+"\n";
}
else{
UngroupedLists +=ListTitle+"\t , \t"+" "+"\t , \t"+ListDefaultviewUrl+"\t , \t"+ title+"\t , \t"+wburl+"\t , \t"+siteOwners+"\t , \t"+modifiedstr+"\n";
}
}
});
//console.log( AllLists);
console.log( AllLibraries);
console.log( UngroupedLists);
}
});
}
function GetItemCount(ListTitle,wburl){
var count=0;
$().SPServices({
operation: "GetListItems",
listName: ListTitle,
async: false,
webURL: wburl,
completefunc: function (xData, status) {
count= $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount") * 1;
}
});
return count;
}
tested in sharepoint 2007 , 2010 & 2013
console.clear();
var jQueryScriptOutputted = false;
function initJQuery() {
if (typeof(jQuery) == 'undefined') {
if (! jQueryScriptOutputted) {
jQueryScriptOutputted = true;
var path = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js";
var sppath = "http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js";
var script = document.createElement( 'script' );
script.src = path;
document.getElementsByTagName( 'head' )[0].appendChild( script );
var spservice = document.createElement('script');
spservice.src= sppath;
document.getElementsByTagName( 'head' )[0].appendChild( spservice );
}
setTimeout("initJQuery()", 100);
}
else {
$(function() { ExecuteRequiredScript(); });
}
}
initJQuery();
var AllLists = "";
function ExecuteRequiredScript(){
GetAllSubWebs();
}
function GetAllSubWebs(){
var count = 0;
console.clear();
$().SPServices({
operation:"GetWebCollection",//GetWebCollection,GetAllSubWebCollection
async: false,
completefunc: function (xData, status) {
console.log(status);
$(xData.responseXML).find("Web").each(function() {
count++;
var title = $(this).attr("Title");
var url = $(this).attr("Url");
console.log(title +"\t" +url );
if(url.indexOf("current weburl") > -1){
getOwnersgrpNAme(title,url);
getUsers(title,url);
}
});
//console.log( AllLists);
console.log(" Sub Webs count \t"+count);
}
});
}
function getCurrentUserRoleforUser(username,url) {//alert(username);
var rolename="";
var counter=0;
$().SPServices({
operation: "GetRoleCollectionFromUser",
userLoginName:username,
webURL:url,
async: false,
completefunc: function (xData, Status) {
if( Status == "success") {
$(xData.responseXML).find("Role").each(function () {
if(counter==0)
{
rolename=$(this).attr("Name");
counter++;
}
else
{
rolename+=";"+$(this).attr("Name");
}
});
}
}
});
return rolename;
}
function getCurrentUserRole(group,url) {
var rolename="";
var counter=0;
$().SPServices({
operation: "GetRoleCollectionFromGroup",
groupName:group,
webURL:url,
async: false,
completefunc: function (xData, Status) {
if( Status == "success") {
$(xData.responseXML).find("Role").each(function () {
if(counter==0)
{
rolename=$(this).attr("Name");
counter++;
}
else
{
rolename+=";"+$(this).attr("Name");
}
});
}
}
});
return rolename;
}
function getUsers(title,url)
{
var perms="";
$().SPServices({
operation: "GetUserCollectionFromWeb",
webURL: url,
async: false,
completefunc: function (xData, Status) {
$(xData.responseXML).find("User").each(function() {
var liHtml = $(this).attr("Name");
perms=getCurrentUserRoleforUser($(this).attr("LoginName"),url);
AllLists += title+"\t"+url+"\t"+perms+"\t"+liHtml+"\t"+"\n";
});
console.log( AllLists);
}
});
}
function getOwnersgrpNAme(title,url){
console.log("Getting Owners");
var siteusers="",rolename="";
$().SPServices({
operation: "GetGroupCollectionFromWeb",
webURL:url,
async: false,
completefunc: function(xData, Status) {
//var AllLists = "";
$(xData.responseXML).find("Group").each(function () {
var name = $(this).attr("Name");
rolename=getCurrentUserRole(name,url);
siteusers=getGroupOwners(title,url,name);
AllLists += title+"\t"+url+"\t"+rolename+"\t"+name+"\t"+siteusers+"\n";
});
console.log( "successuser1");
}
});
//return siteowner;
}
function getGroupOwners(title,url,groupName) {
var ownerdata = "";
// Gets users within Owners group
$().SPServices({
operation: "GetUserCollectionFromGroup",
groupName: groupName,
webURL:url,
async: false,
completefunc: function (xData, Status) {
//alert(groupName+" "+Status);
$(xData.responseXML).find("User").each(function () {
var displayName = $(this).attr("Name");
if(ownerdata ==""){
ownerdata =displayName ;
}
else{
ownerdata =ownerdata +";"+displayName ;
}
});
}
});
return ownerdata;
}
function GetAllListsIntheSite(wburl,title,siteOwners){
$().SPServices({
operation: "GetListCollection",
webURL:wburl,
async: false,
completefunc: function( xData, Status ) {
var AllLists = "",AllLibraries = "",UngroupedLists = "";
$( xData.responseXML ).find("Lists > List").each(function() {
var $node = $(this);
var ListTitle = $node.attr("Title");
var ListDefaultviewUrl = $node.attr("DefaultViewUrl");
var modified = $node.attr("Modified");
var modifiedstr=modified.substr(4,2)+"/"+modified.substr(6,2)+"/"+modified.substr(0,4)+" "+modified.substr(9,2)+":"+modified.substr(12,2);
if(ListDefaultviewUrl.indexOf("/_catalogs/")== -1){
if(ListDefaultviewUrl.indexOf("/Lists/") > 0){
var itemCount=GetItemCount(ListTitle,wburl);
AllLists += ListTitle+"\t , \t"+"List"+"\t , \t"+ListDefaultviewUrl+"\t , \t"+title+"\t , \t"+wburl+"\t , \t"+siteOwners+"\t , \t"+modifiedstr+"\t , \t"+ itemCount +" Items"+"\n";
}
else if(ListDefaultviewUrl.indexOf("/Forms/") > 0){
AllLibraries +=ListTitle+"\t , \t"+"Document Library"+"\t , \t"+ListDefaultviewUrl+"\t , \t"+ title+"\t , \t"+wburl+"\t , \t"+siteOwners+"\t , \t"+modifiedstr+"\n";
}
else{
UngroupedLists +=ListTitle+"\t , \t"+" "+"\t , \t"+ListDefaultviewUrl+"\t , \t"+ title+"\t , \t"+wburl+"\t , \t"+siteOwners+"\t , \t"+modifiedstr+"\n";
}
}
});
//console.log( AllLists);
console.log( AllLibraries);
console.log( UngroupedLists);
}
});
}
function GetItemCount(ListTitle,wburl){
var count=0;
$().SPServices({
operation: "GetListItems",
listName: ListTitle,
async: false,
webURL: wburl,
completefunc: function (xData, status) {
count= $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount") * 1;
}
});
return count;
}
No comments:
Post a Comment