Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Anybody know how to do batch list updates with the javascript client object model in Sharepoint 2010? I'm putting the list into an array right now and then a kendo grid is reading it. I can update the grid and it'd be nice to push the updates back to the list without having to call update or create events on every update.

    var context = null,
    web = null,
    currentUser = null,
    menuList = null,
    expenseListItems = [],
    menuItems;


    function getCurrentItems() {

    context = SP.ClientContext.get_current();
    web = context.get_web();
    menuList = web.get_lists().getByTitle('ExpenseReportItems');
    var query = SP.CamlQuery.createAllItemsQuery();
    menuItems = menuList.getItems(query);
    context.load(menuItems, "Include(Title, ID)");
    context.executeQueryAsync(onGridLoadSuccess, onFail);
 }

    function onGridLoadSuccess() {

    var listEnum = menuItems.getEnumerator();
    while (listEnum.moveNext()) {

    var event = listEnum.get_current();

    var Title = event.get_item('Title');
    var ID = event.get_item('ID');

    var expenseData = { title: Title, id: ID };
        expenseListItems.push(expenseData);
    }

    buildGrid(expenseListItems);
}
share|improve this question
    
So what your saying is that your want to create in memory collection of changes that you have done to all items in the list. And when the users is done with it's changes. Then you want them to be persisted? –  Robban1980 Aug 14 '12 at 2:34
    
That's the jist of it. Don't know if it's possible or not. –  CeeMoney Aug 14 '12 at 12:14
add comment

2 Answers

Some questions to help you on your way:

  • If you don't want to send anything to the server between item edits, how will you store it client side? Hidden fields or some other way?
  • If you will store the collection on server side before persisting it, you could store it in a session or something else?
  • How will you handle integrity of data if multiple people edit the same item with a batch job? first come first or some more complicated way?
  • How will you handle validation of data before persisting and when persisting?
  • How will you know when to save the data? Will there be an extra button for the user to click on when they are done editing?
  • Is your idea a good way of doing it? why don't you want to send the item to the server when the user is done ediditng it? do you have performance issues at the moment or are you expecting to get them in a near future?

and to answer your last question if it is possible: Of course it is possible to do a batch save. But i have to point back to my last question.

share|improve this answer
add comment

I strongly recommend u start by monitoring menuItems with a debugger, since this is your global variable that stores the Items.

At the end you could write some code like this:

function saveChanges() {
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle("ExpenseReportItems");
    jQuery.each(menuItems, function(index, menuItem) {
        var item = list.getItemById(menuItem.id);
        item.set_item('Title', menuItem.get_item('Title'));
        item.update();
        context.executeQueryAsync(null, function(sender, args) {SP.UI.Notify.addNotification('could not save ListItems. Error: ' + args.get_message())});
    });
}

I hope this helps u, you can of course try to flag your menuItems when they are changed by the user and only save those (for better performance).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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