February 6, 2017

How To Select More Than 100 Items in SharePoint List View

SharePoint has a limit for the number of batch operations allowed. Below is how can we overcome it.

The Issue:
You have a list or library, you modifies the list view to show 120 items (or any number larger than 100). Then you click the check all icon to select all items on view. When you click 'Delete Item' in ribbon, a popup appears with "You cannot select more than 100 items at once."

What does Microsoft day?
From this technet pagein List and library limits:
Bulk operations
100 items per bulk operation
The user interface allows a maximum of 100 items to be selected for bulk operations.

The truth is out there:
Based on a similar post here, I decided to take a deeper understanding and provide a more solid solution. I put the SharePoint list view under developer mode to inspect the js functionality and found the variables I was looking for:

From Strings.debug.js:
Strings.STS.L_BulkSelection_TooManyItems='You cannot select more than 100 items at once.';

From Core.debug.js:
g_MaximumSelectedItemsAllowed = 100;

On page load, the RenderSelectAllCbx() method will be called to add toggle functionality on every selection control element including the 'Delete Item' in ribbon. Below is the callstack:

RenderSelectAllCbx(renderCtx, ret)   (in ClientTemplates.debug.js) >
ToggleAllItems(evt, cbx, ctxNum)   (in Init.debug.js) >
CoreInvoke('_ToggleAllItems', evt, cbx, ctxNum)   (in Init.debug.js) >
_ToggleAllItems(evt, cbx, ctxNum)   (in Core.debug.js) >
ToggleAllItems2(cbx, ctxNum, f)   (in Core.debug.js)

The last function will throw the popup alert when more than 100 items selected for deletion
        if (totalItems > g_MaximumSelectedItemsAllowed) {
            cbx.checked = false;

Beta Solution:
So we just need a custom js to overwrite the 'MaximumSelectedItemsAllowed ' variable and set a new value, right?

1.  Create a new js file under 15 hive:

2. Edit the file:

function changeItemSelect() {
               g_MaximumSelectedItemsAllowed = 120;
               Strings.STS.L_BulkSelection_TooManyItems= "You cannot select more than "           +   g_MaximumSelectedItemsAllowed + " items at once.";

3. On target page or list view, add Script Editor web part (or CEWP) and edit source:
<script src="/_layouts/15/jquery-1.11.2.min.js" type="text/javascript"></script>

<script language="Javascript" src="/_layouts/15/CustomUI/ItemSelectLimit.js?rev=1" type="text/javascript"></script>

Test #1:
     - Modify list view to show 120 items then clicked delete. It will work without an issue. All deleted items went to Site recycle bin.
    - Modify list view to show 200 items then clicked delete. It showed the error popup as expected.

4. In our custom ItemSelectLimit.js file, set MaximumSelectedItemsAllowed to 300
Test #2:
    - Modify list view to show 200 items then clicked delete. It worked without an issue. All deleted items went to Site recycle bin.
 - Modify list view to show 300 items then clicked delete. It did not work! the page did not refresh and the selected items were not deleted (not even partially deleted).

Below is excerpt from ULS log:
 Name=Request (POST:{SiteUrl}/_vti_bin/client.svc/ProcessQuery)

 Begin CSOM Request ManagedThreadId=8, NativeThreadId=20404
 Original error: Microsoft.SharePoint.Client.ClientServiceException: The request uses too many resources.     at Microsoft.SharePoint.Client.ClientMethodsProcessor.Process()
RequestMessage: <Request xmlns="" SchemaVersion="" LibraryVersion="" ApplicationName="Javascript Library"><Actions>................... 

Any fix for that?
Yes. Check my previous post for complete analysis & solution.

The Final Solution:
Before you begin any changes, make sure you understand the performance impact and requirements for your environment.

1. Client Side:
Follow same steps 1, 2 & 3 from Beta Solution above.

2. Server Side:
   Use PowerShell to check existing value of MaxObjectPaths property for target web application.
   If total number of items to be deleted or updated (g_MaximumSelectedItemsAllowed) > (MaxObjectPaths - 4) then set a larger value for MaxObjectPaths:

$WebApp.ClientCallableSettings.MaxObjectPaths = $g_MaximumSelectedItemsAllowed + 4


·        The above technique does not work for Quick Edit view because it uses different set of js files & do not use ‘g_MaximumSelectedItemsAllowed’ variable.