Working around SharePoint 2010’s 5,000 item view limits

 Computer, Sharepoint, Software  Comments Off on Working around SharePoint 2010’s 5,000 item view limits
Jan 082016
 

Update 1/13/2016 – Changes to script. The original script hides the list view pagination. Changes marked as Pagination Fix below.

I have a SharePoint list that has exceeded the 5,000 item limit threshold. This, of course, causes a couple of views to go bonkers.
MeetMe

I indexed several list columns but the client still needs to be able to filter the entire list. I wrote some jQuery to replace that awful message shown above.

<script src="jquery-1.10.1.min.js"></script>
<script type="text/javascript">
// jQuery extension
(function($){
    $.fn.extend({
        removeByContent: function(str) {
           return this.each(function(){
                var self = $(this);
                if(self.html().indexOf(str) != -1) self.hide();
            });
        }
    });
})(jQuery);
// jQuery Show function added 1.13.2016
(function($){
    $.fn.extend({
        showByContent: function(str) {
           return this.each(function(){
                var self = $(this);
                if(self.html().indexOf(str) != -1) self.show();
            });
        }
    });
})(jQuery);
// Script to remove the error message text.
$('.ms-vb').removeByContent('This view cannot');
$('.ms-vb').removeByContent('Operations that exceed');
$('.ms-vb').removeByContent('Learn about'); 
/* Pagination Fix if needed 
$('.ms-vb').removeByContent('try selecting another view'); 
$('.ms-vb').showByContent('Next');
*/
</script>

<script type="text/javascript">
// Remove this script if list view pagination needed and add Fix lines above.
// Let's replace one of those lines with instructions for the user.
$(document).ready(function() {
     $(".ms-vb").text(function(index,text) {
      return text.replace('To view items, try selecting another view or creating a new view. If you do not have sufficient permissions to create views for this list, ask your administrator to modify the view so that it conforms to the list view threshold.','Please select a filter above.');
   });
});
</script>



Even though SharePoint is complaining in the background, selecting a filter will return results to the list web part.

MeetMe2

Managing SharePoint User Group Memberships with JQuery and SPServices

 Computer, Sharepoint, Software  Comments Off on Managing SharePoint User Group Memberships with JQuery and SPServices
Dec 162015
 

Create a simple interface to add/remove a single user to/from multiple groups at once. When you identify/select a user, it will show you two select lists. The right side will list all of the groups the current user is a member of while the left box shows all the groups the user is NOT a member of. Between the two select lists are buttons to ‘move’ the groups from one side to the other for the identified user (while modifying their memberships appropriately in the process). The select boxes are configured to allow multiple select so you can usually perform the maintenance in just a couple clicks.

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

<table width="100%" class="ms-rteTable-default ms-rteThemeBackColor-5-5 ms-rteThemeForeColor-1-0 ms-rteFontSize-2" cellspacing="0" _moz_resizing="true" style="font-size: 1em">
<tbody>
<tr class="ms-rteTableHeaderRow-default ms-rteThemeBackColor-5-5 ms-rteThemeForeColor-1-0 ms-rteFontSize-2"><th class="ms-rteTableHeaderFirstCol-default ms-rteThemeBackColor-5-5 ms-rteThemeForeColor-1-0 ms-rteFontSize-2" rowspan="1" colspan="1" style="text-align: left"><span>User Group Membership</span></th></tr></tbody></table>

<script type="text/javascript">

$(document).ready(function() {
//Populate the users pick list
  var strHTMLSiteUsers = "";
  $().SPServices({
      operation: "GetUserCollectionFromSite",
      async: false,
      completefunc: function(xData, Status) {
        $(xData.responseXML).find("User").each(function() {
        strHTMLSiteUsers += "<option value='" + $(this).attr("LoginName") + "'>" + $(this).attr("Name") + "</option>";
        });
        $("#my_SiteUsers").append(strHTMLSiteUsers);
  		//	$("#xmlOutput").append("<textarea rows='15' cols='100'>" + xData.responseXML.xml + "</textarea>");
		//	$("#groupOutput").append("<textarea rows='15' cols='100'>" + strHTMLSiteUsers  + "</textarea>");
      }
});
  RefreshGroupLists();
});

function RefreshGroupLists(){
  var strHTMLAvailable = "";
  var strHTMLAssigned = "";
  var arrOptionsAssigned = new Array();
  var intOpts = 0;
  var booMatch;
  var booErr = "false";
  var SelectedUser = $('#my_SiteUsers').val();
 // alert(SelectUser);


  $("#my_SPGroupsAssigned").html("");
  $("#my_SPGroupsAvailable").html("");

  if($("#my_SiteUsers").val() == 0){
    alert("You must select a user");
    return;
  }

  //Populate the Groups Assigned

  $().SPServices({
      operation: "GetGroupCollectionFromUser",
      userLoginName: $('#my_SiteUsers').val(),
      async: false,
      completefunc: function(xData, Status) {
        $(xData.responseXML).find("errorstring").each(function() {
          alert("User not found");
          booErr = "true";
          return;
        });
      
        $(xData.responseXML).find("Group").each(function() {


          strHTMLAvailable += "<option value='" + $(this).attr("Name") + "'>" + $(this).attr("Name") + "</option>";
          arrOptionsAssigned[intOpts] = $(this).attr("Name");
          intOpts = intOpts + 1;
        });
        $("#my_SPGroupsAssigned").append(strHTMLAvailable);
      }
  });

  //Populate available site groups
  if(booErr == "false"){
    $().SPServices({
        operation: "GetGroupCollectionFromSite",
        async: false,
        completefunc: function(xData, Status) {
          $(xData.responseXML).find("Group").each(function() {
            booMatch = "false";
            for (var i=0;i<=arrOptionsAssigned.length;i++){
              if($(this).attr("Name") == arrOptionsAssigned[i]){
                booMatch = "true";
                break;
              }
            }
            if(booMatch == "false"){
              strHTMLAssigned += "<option value='" + $(this).attr("Name") + "'>" + $(this).attr("Name") + "</option>";
            }
          });
          $("#my_SPGroupsAvailable").append(strHTMLAssigned);
        }
    });
  }
}

function AddGroupsToUser(){
  var i;

  if($("#my_SiteUsers").val() == 0){
    alert("You must select a user");
    return;
  }

  if($("#my_SPGroupsAvailable").val() == null){
    alert("You haven't selected any groups to add");
    return;
  }
  else{
    var arrGroups = $("#my_SPGroupsAvailable").val();
      var SelectedUser = $('#my_SiteUsers').val();
     alert(SelectedUser);
      alert(arrGroups);
    for (i=0;i<arrGroups.length;i++){
      $().SPServices({
          operation: "AddUserToGroup",
          groupName: arrGroups[i],
          userLoginName: $('#my_SiteUsers').val(),
          async: false,
          completefunc: null
      });
    }
    RefreshGroupLists();
  }
}

function RemoveGroupsFromUser(){
  var i

  if($("#my_SiteUsers").val() == 0){
    alert("You must select a user");
    return;
  }

  if($("#my_SPGroupsAssigned").val() == null){
    alert("You haven't selected any groups to remove");
    return;
  }
  else{
    var arrGroups = $("#my_SPGroupsAssigned").val();
    var SelectedUser = $('#my_SiteUsers').val();
    
    for (i=0;i<arrGroups.length;i++){
      $().SPServices({
          operation: "RemoveUserFromGroup",
          groupName: arrGroups[i],
          userLoginName: $('#my_SiteUsers').val(),
          async: false,
          completefunc: null
      });
    }
    RefreshGroupLists();
  }
}</script>

<table align="center">
<tbody>
<tr>
<td colspan="3" style="text-align: center">
<font style="font-weight: bold">Select a User:&#160;&#160;&#160;</font> <select id="my_SiteUsers" onchange="RefreshGroupLists()" style="width: 350px"></select>
</td></tr>
<tr><th class="ms-vh2">Available Groups</th>
<th></th>
<th class="ms-vh2">Assigned Groups</th></tr>
<tr><td class="ms-vb2">
<select id="my_SPGroupsAvailable" multiple="multiple" style="height: 450px; width: 250px"></select> 
</td>
<td><button id="my_AddGroupsToUser" onclick="AddGroupsToUser()" type="submit" style="width: 80px">&gt;&gt;</button><br/><br/><button id="my_RemoveGroupsFromUser" onclick="RemoveGroupsFromUser()" type="submit" style="width: 80px">&lt;&lt;</button>
</td>
<td class="ms-vb2"><select id="my_SPGroupsAssigned" multiple="multiple" style="height: 450px; width: 250px"></select> 
</td>
</tr>
</tbody>
</table>
<!--- For Debugging Purposes --->
<div id="xmlOutput"></div>
<div id="groupOutput"></div>

image_thumb