Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Adding Multiple Items to List

$
0
0

Hello Experts! I have some code (JavaScript) which adds multiple list items from an excel sheet. Data is converted to CSV and from there relevant data is extracted and list items need to be created, i know the csv conversion part is fine but I notice in my list i only see one item being added and the rest is not. I get a generic error message Operation Aborted or timed out on my second call to

executeQueryAsync

. I have tried both the deferred/promise way and the call back method to batch up the creation of items but its the same result. Any ideas how to troubleshoot this further , i would like to know why its getting aborted.

Here is snippet of my code.

//input is my CSV file data as array

ProcessData = function (input) { var clientContext = new SP.ClientContext.get_current(); var oList = clientContext.get_web().get_lists().getByTitle('myList'); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml( '<View>' + '<Query>' + '<Where>' + '<And>' + '<Eq>' + '<FieldRef Name="myField1" />' + '<Value Type="Text">' + field1 + '</Value>' + '</Eq>' + '<Eq>' + '<FieldRef Name="myField2" />' + '<Value Type="Text">' + field2 + '</Value>' + '</Eq>' + '</And>' + '</Where>' + '</Query>' + '</View>' ); var listItems = oList.getItems(camlQuery); clientContext.load(listItems); clientContext.executeQueryAsync(OnCheckExistingSucceeded, OnCheckExistingFailed); function OnCheckExistingSucceeded(sender, args) { if (listItems.get_count() > 0) { out.innerText += "Already exists " + field1 + " - " + field2; } else { for (i = 0; i < input.length; i++) { if (input[i].length > 2 && !isNaN(input[i][2]) && input[i][2] != "") { var itemCreateInfo = new SP.ListItemCreationInformation(); var oListItem = oList.addItem(itemCreateInfo); oListItem.set_item('field3', input[i][3]); oListItem.set_item('field4', input[i][4]); oListItem.set_item('field5', input[i][5]); oListItem.update(); clientContext.load(oListItem); } } clientContext.executeQueryAsync(OnQuerySucceeded, OnQueryFailed); function OnQuerySucceeded() {out.innerText += "Successfully upload";} function OnQueryFailed(sender, args) {out.innerText += "\nUploading Error: " + args.get_message();} } } function OnCheckExistingFailed(sender, args) { out.innerText += "\n Error: " + args.get_message(); } };



Viewing all articles
Browse latest Browse all 7589

Trending Articles



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