Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

Batch creation of list items with Javascript object model

$
0
0

this.SaveAllNewKeywords = function SaveAllNewKeywords(keywords) {
        //TODO this function should use Deferred, and return promise        

        var clientContext = new SP.ClientContext.get_current();
        var web = clientContext.get_web();
        var listCollection = web.get_lists();
        var list = listCollection.getById(this.LIST_ID_KEYWORD);
        var l = keywords.length;
        var keyword;
        var keywordsToSave = new Array();

        for (var i = 0; i < l; i++) {
            keyword = keywords[i];
            if (keyword.id == "-1") {
                // TODO save this keyword to list using CSOM and deferred
                var itemCreateInfo = new SP.ListItemCreationInformation();
                var listItem = list.addItem(itemCreateInfo);
                keywordsToSave.push(listItem);
                listItem.set_item('Title', keyword.value);
                listItem.set_item('SCP_KeywordValue', keyword.value);
                listItem.update();
                clientContext.load(listItem);
                //this.SaveNewKeyword(keyword, list, clientContext, keywordsToSave);

            };
        }
        clientContext.executeQueryAsync(function () {
            alert('suc');
        }, function () {
            alert('error');
        });
    }

The above function is creating list items but error(failure) call back is being executed. I have no clue though i have spent many hours on this. Any help is much appreciated.

               

Venkatesh Kadiri


Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>