1

I have found this code to perform batch update

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();

But I am getting the following error :

The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

I need to update a various item in the list without iterating it.

Please Help!!

1 Answer 1

1

Should you check this code

Create a new function and rename it as bulkupdate

Function BulkUpdate()
{

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

}
}


    var siteUrl = '/sites/MySiteCollection';

    function updateListItem(int i) {

        var clientContext = new SP.ClientContext(siteUrl);
        var oList = clientContext.get_web().get_lists().getByTitle('Announcements');


 this.oListItem = oList.getItemById(i);

        oListItem.set_item('Title', 'My Updated Title');

        oListItem.update();

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

    function onQuerySucceeded() {

        alert('Item updated!');
    }

    function onQueryFailed(sender, args) {

        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
7
  • Thanks buddy i found the solution.....but my new problem is i have to compare the item column with the new value......and i am getting this error not while set_item method but while get_item method....help plss...if u want i can share the code in next question
    – Shomit
    Jul 18, 2016 at 9:50
  • and do not worry brother with that much of help...i will definetely vote your answer and mark correct
    – Shomit
    Jul 18, 2016 at 9:51
  • Hey buddy posted new....please help
    – Shomit
    Jul 18, 2016 at 10:08
  • Should you update your question with the new request please ? don't worry I am here to do my best and help you Jul 18, 2016 at 10:13
  • 1
    Note: Function.createDelegate() is oldskool IE code: sharepoint.stackexchange.com/questions/164893/… Jul 18, 2016 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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