0

I'm trying to update a field using CSOM. It works for few items but when i try t on items over 700 items i'm getting the error below:-

"The request message is too big. The server does not allow messages larger than 2097152 bytes"

Is this normal as these items are small? See the code below. How can i turn the code below to update in batches?

  function updateListItems() {

    // Create an instance of the current context to return context information
    clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('Test');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query></Query></View>');
    this.collListItem = oList.getItems(camlQuery);   
    clientContext.load(oList);
    clientContext.load(collListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));


}

function onQuerySucceeded() {

    var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext()) 
    {   
        var item = listItemEnumerator.get_current(); 
        item.set_item("TestUnit", "TestUnit");
        //Commits changed properties of the list item
        item.update();

    }   

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onUpdateSucceeded), Function.createDelegate(this, this.onQueryFailed));

}

Thanks in Advance

0

You can use Batch Update Items from List:

function updateListItems() {

var itemArray = [];
var clientContext = SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('TestList');


for(var i = 1; i<= 5; i++){

    var oListItem = oList.getItemById(i);  
    oListItem.set_item('Title', 'My Updated Item!' + i);  
    oListItem.update();
    itemArray[i] = oListItem;
    clientContext.load(itemArray[i]);
}

clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}

function onQuerySucceeded() {

alert('Items Updated');
}

function onQueryFailed(sender, args) {

alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

updateListItems();

Reference from

  • Thanks Sunil for your response.But the issue is if the item id that is being passed to getitemid doesn't exist it fails. – naijacoder Oct 10 '18 at 11:22
  • How can this be achieved in batches of 50 or 100 or 500 using the script? – naijacoder Oct 10 '18 at 21:56
  • for batch only you need iterate clientContext.load and after all items you need to clientContext.executeQueryAsync. check if(itemid) prior getting into the iteration – Sunil Sahu Oct 11 '18 at 10:11
  • Thanks Sunil can you please be more specific .Maybe with a snippet code – naijacoder Oct 12 '18 at 0:15
  • Hi Sunil, Any update on this? – naijacoder Nov 23 '18 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.