GetAllUserCollectionFromWeb

Sep 10, 2010 at 11:39 PM
Edited Sep 10, 2010 at 11:40 PM

How do I get the Login name based on the URL i got from the first search?

 

var Edit = false;

  // Global var for Grid content
var GridContent = new Array();
  // Global var for counter
var giCount = 0;
var i = 0;
 
var prLogin = new Array();
var out = new Array();
var account = new Array();
var testaccount = new Array();
var permission = new Array();
 
//var thisSite = $().SPServices.SPGetCurrentSite();
//alert(out.length);


var ScopeUrl = $().SPServices({
    operation: "GetAllSubWebCollection",
    webUrl: "/",
    completefunc: function (xData, Status) {
$(xData.responseXML).find("Web").each(function() {

   
      out[i]=$(this).attr("Url");
      i++;
 //alert(out);
  
});
     }
 });

//alert(out);

//alert(getUrlfromout);

//for(i = 0; i < out.length; i++)
//{
//alert(out[i]);
for(i=0; i<out.length; i++) {
$().SPServices({
    operation: "GetAllUserCollectionFromWeb",
    webUrl: "out[i]",
    completefunc: function (xData, Status) {
$(xData.responseXML).find("User").each(function() {
 
      //if (out == $(this).attr("Url"))
      //{
      testaccount[i]=$(this).attr("LoginName");
      //}
   

 //alert(out);
  
});
     }
 });

}

for(i=0; i<out.length; i++) {
$().SPServices({
    operation: "GetAllUserCollectionFromWeb",
    webUrl: out[i],
    completefunc: function (xData, Status) {
$(xData.responseXML).find("User").each(function() {
 
   
      permission[i]=$(this).attr("RoleName");
   
   

 //alert(out);
  
});
     }
 });

}


//}


    var wwid = $().SPServices({
    operation: "GetUserProfileByName",
    accountName: testaccount[i],
    async: false,
    completefunc: function (xData, Status) {
$(xData.responseXML).find("PropertyData").each(
    function()
     {
        
         if (($(this).find("Name").text()) === "Title")
           {
         title = $(this).find("Value").text();

           }
          
            if (($(this).find("Name").text()) === "Manager")
           {
         manager = $(this).find("Value").text();

           }

        

    });
     
     }
 });
 
//ert(testaccount[i]);


                          $(document).ready(function() {
                          for(i = 0; i < out.length; i++){

                          GridContent[giCount] = new Array(7);
                          GridContent[giCount][0] = out[i];
                          GridContent[giCount][1] = testaccount[i];
                          GridContent[giCount][2] = title;
                          GridContent[giCount][3] = title;
                          GridContent[giCount][4] = manager;
                          GridContent[giCount][5] = title;
                          GridContent[giCount][6] = permission[i];
                          giCount++;
                          }         //     "ows_owshiddenversion"
                         

  });

  // oTabel.fnAddData( GridContent, true);
  // oTable.fnDraw();



</script>

<script type="text/javascript">

  $("#tabl_wrapper").css("width","100%");
  $("#tabl").css("width","100%");

  // Global variable for the DataTables object
  var oTable;

 

  /* Formating function for row details */
  function fnFormatDetails ( nTr )
  {
        var aData = oTable.fnGetData( nTr );
        var sOut = ''
        // sOut += '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:250px;">';
        sOut += '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:5px;">';
        sOut += '<tr><td>Permission Scope URL                       :</td><td>' + aData[0]  + '</td></tr>';
        sOut += '<tr><td>Domain Group            :</td><td>' + aData[1]  + '</td></tr>';
        sOut += '<tr><td>SharePoint Group                   :</td><td>' + aData[2]  + '</td></tr>';
        sOut += '<tr><td>Manager                     :</td><td>' + aData[3]  + '</td></tr>';
        sOut += '<tr><td>testID  :</td><td>' + aData[4] + '</td></tr>';
           sOut += '<tr><td>Permission   :</td><td>' + aData[5] + '</td></tr>';
        sOut += '</table>';

               return sOut;
  }

  $(document).ready(function() {

        //                 "sDom": 'T<"clear"><"top"ifl<"clear">>rt<"bottom"p<"clear">>',

        oTable=$('#splist').dataTable( {
                "bPaginate": true,
                "bJQueryUI": true,
                "bLengthChange": true,
                "bAutoWidth": false,
                "bFilter": true,
                "bSort": true,
                "bInfo": true,
                "sPaginationType": "full_numbers",
                "iDisplayLength": 25,
                "sDom": 'T<"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr>t<"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>',

                "aaData": GridContent,
                "aoColumns": [
                  { "sTitle": "Permission Scope URL" },
                        { "sTitle": "Account" },
                        { "sTitle": "Domain Group" },
                        { "sTitle": "SharePoint Group" },
                        { "sTitle": "Manager" },
                        { "sTitle": "testID" },
                        { "sTitle": "Permission" }                ],
                "aaSorting": [ [1,'asc'], [2,'asc'] ],
                "bProcessing": true,
                "bStateSave": true,
                "sSearch": true,
                "bServerSide": false
          });

          // Fixed Header
         new FixedHeader( oTable );

        /* Add event listener for opening and closing details
         * Note that the indicator for showing which row is open is not controlled by DataTables,
         * rather it is done here
         */
        $('td img', oTable.fnGetNodes() ).each( function () {
                $(this).click( function () {
                        var nTr = this.parentNode.parentNode;
                        if ( this.src.match('details_close') )
                        {
                                /* This row is already open - close it */
                                this.src = "images/details_open.png";
                                oTable.fnClose( nTr );
                        }
                        else
                        {
                                /* Open this row */
                                this.src = "images/details_close.png";
                                oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
                        }
                } );
        } );

  } );

</script>

<table id="splist" class="display">
 <tbody id="tablebody">
  <!-- GetListsItem write data here -->
 </tbody>
</table>

Coordinator
Sep 13, 2010 at 8:55 PM

I don't think I understand what you're trying to do. Login name is going to be the same all the time as the web services run as the logged in user. There's a OOTB JavaScript variable containing the username, or you can make a $().SPServices.SPGetCurrentUser call, but it doesn't matter when you make that call.

Maybe I'm missing what you're trying to do.

Sep 13, 2010 at 10:17 PM

I'm trying to get all the users information from site collection, including web url and their roles.

Coordinator
Sep 14, 2010 at 1:02 AM

Ok, so you want to iterate through all of the site collections and output the site URL; then query the permissions service for that URL to get a list of users.

There's a security scope issue, that may or may not be an issue for you. Marc may chime in and clarify, but I believe this will only work for a farm administrator. The web services use the permissions of the logged in user, so only someone with permissions to see all of the collections will be able to run this. The only reason I bring it up, is because if you're making a table of contents or a nav bar of sorts, it's probably not going to meet your needs.

Sep 14, 2010 at 1:28 AM

That's correct, I want to iterate through all of the site collections and output the site URL; then query the permissions service for that URL to get a list of users.

About the permission issue. Do you know why sometimes I can get the information back and sometimes I get access denied. For me it doesnt make sense. It looks like there is a cycle through the permission.

When it is working I can get almost all the output I need it.

Coordinator
Sep 14, 2010 at 1:39 AM

If you're a farm administrator it should work for you all the time. If you're seeing access denied errors it sounds like you're not really a farm administrator, like it's hitting a site collection that you're not an admin on.

If you're using this just as reporting for your own purposes, then a little overhead is probably acceptable. In that scenario you probably need another step.

  1. Get list of Site Collections on farm
  2. Iterate through site collections to get list of groups
  3. Query each group to get each username in it

You also probably want to make sure you set the async option in your SPServices calls to false; to make sure they don't get out of sync and try and call out of order. They should all be within a loop, but setting async to false is probably a good idea. It may be possible that your access denied error is a result of a site or two that has more data, straggling behind the rest and calling out of order- just a thought.

Sep 14, 2010 at 1:47 AM

Thank you I will try that

Sep 22, 2010 at 3:44 AM

I got mine working like a charm. I like this library and I dont need to have SharePoint farm administrator to be able to see the information.

Does this library working for WSS 3.0 without MOSS?

Coordinator
Sep 22, 2010 at 3:50 AM
I do my first testing on WSS and then MOSS for the Web Services which are only available there. I've also done *some* testing with SP2010, but need to do much more. There are icons throughout the docs which indicate what each function is 'certified' for. N.
Sep 22, 2010 at 3:52 AM
Edited Sep 22, 2010 at 4:23 AM

By the way I have sample for GetUserProfileByName using Jquery

$().SPServices({
    operation: "GetUserProfileByName",
    accountName: "Domain\account"
    async: false,
    completefunc: function (xData, Status) {
$(xData.responseXML).find("PropertyData").each(
    function()
     {
        
         if (($(this).find("Name").text()) === "Title")
           {
         title = $(this).find("Value").text();

           }
          
            if (($(this).find("Name").text()) === "Manager")
           {
         manager = $(this).find("Value").text();

           }

        

    });
     
     }
 });