I am trying save the below into list in SharePoint, but each item is getting saved twice. I need to save only once. What's wrong?
function sumcalval() {
alert("save function called");
var pageload1 = 0;
var rowCount1 = $("#data_table_1 tbody tr").length;
alert("rowCount1 "+rowCount1);
var rowcountgrid1 = rowCount1;
alert("rowcountgrid1 " + rowcountgrid1);
for (var j = 0; j < rowCount1; j++) {
gridval1 = $("#row" + j).find(".projectcode").val();
alert("gridval1 " + gridval1);
gridval2 = $("#row" + j).find(".projectname").val();
alert("gridval2" + gridval2);
gridval3 = $("#row" + j).find(".atlaspartno").val();
alert("gridval3" + gridval3);
gridval4 = $("#row" + j).find(".atlasdescription").val();
alert("gridval4" + gridval4);
gridval5 = $("#row" + j).find(".stdnstd").val();
alert("gridval5" + gridval5);
gridval6 = $("#row" + j).find(".mfgpur").val();
alert("gridval6" + gridval6);
gridval7 = $("#row" + j).find(".finalqty").val();
gridval8 = $("#row" + j).find(".uom").val();
gridval9 = $("#row" + j).find(".qtyatquotequotedcogs").val();
alert("gridval9" + gridval9);
gridval10 = $("#row" + j).find(".unitratequotedcogs").val();
gridval11 = $("#row" + j).find(".totalquotedcogs").val();
gridval12 = $("#row" + j).find(".targetunitcost").val();
gridval13 = $("#row" + j).find(".targetcosttotal").val();
gridval14 = $("#row" + j).find(".rswp").val();
gridval17 = $("#row" + j).find(".unitratepocosttracking").val();
gridval18 = $("#row" + j).find(".pocosttotaltracking").val();
gridval19 = $("#row" + j).find(".rswptracking").val();
gridval20 = $("#row" + j).find(".unitraterevenue").val();
gridval21 = $("#row" + j).find(".totalrevenue").val();
// TotalRevenue = TotalRevenue + gridvalue21;
var ctx = new SP.ClientContext(appweburl);//Get the SharePoint Context object based upon the URL
var appCtxSite = new SP.AppContextSite(ctx, hostweburl);
var web = appCtxSite.get_web(); //Get the Site
var list = web.get_lists().getByTitle("wbslist"); //Get the List based upon the Title
var listCreationInformation = new SP.ListItemCreationInformation(); //Object for creating Item in the List
var oListItem11 = list.addItem(listCreationInformation);
oListItem11.set_item('wbscode', QueryStringValue);
oListItem11.set_item('projectcode', listItemInfo1);
oListItem11.set_item('projectname', listItemInfo2);
oListItem11.set_item('WBSTaskno', gridvalue1);
//oListItem1.set_item('TaskCategory', gridvaluecat);
oListItem11.set_item('TaskName', gridval2);
oListItem11.set_item('atlaspartno', gridval3);
oListItem11.set_item('atlasdescription', gridval4);
oListItem11.set_item('stdnstd', gridval5);
oListItem11.set_item('mfgpur', gridval6);
oListItem11.set_item('finalqty', gridval7);
oListItem11.set_item('uom', gridval8);
oListItem11.set_item('qtyatquotequotedcogs', gridval9);
oListItem11.set_item('unitratequotedcogs', gridval10);
oListItem11.set_item('totalquotedcogs', gridval11);
oListItem11.set_item('targetunitcost', gridval12);
oListItem11.set_item('targetcosttotal', gridval13);
oListItem11.set_item('rswp', gridval14);
//oListItem1.set_item('ponoitemwisefilledbypro', gridvalue15);
oListItem11.set_item('unitratepocosttracking', gridval17);
oListItem11.set_item('pocosttotaltracking', gridval18);
oListItem11.set_item('rswptracking', gridval19);
oListItem11.set_item('unitraterevenue', gridval20);
oListItem11.set_item('totalrevenue', gridval21);
oListItem11.update(); //Update the List Item
ctx.load(oListItem11);
ctx.executeQueryAsync(function () {
pageload++;
if (pageload == rowcountgrid) {
alert("Saving Completed");
}
}, 1);
}
}