Hi I have this issue where not all records are being saved to the SharePoint List coming from my array , sometimes all records was saved.
see below code that i used
function savetoDetailList(id) {
globalAuditTrailArr.forEach((a) => {
var today = new Date();
var qyear = today.getFullYear();
var qmonth = today.getMonth();
var ctx = new SP.ClientContext.get_current();
var oList = ctx.get_web().get_lists().getByTitle("DetailList");
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item("Title", a.Title);
oListItem.set_item("FIELD_x0020_DESCRIPTION", a.fieldDesc);
oListItem.set_item("MainID", id); //MainList/Parent ListID
oListItem.update();
ctx.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
});
}
function onQuerySucceeded(sender, args) {
window.location.replace(siteurl + "/Lists/DetailList/AllItems.aspx");
}
function onQueryFailed(sender, args) {
console.log("Request failed.");
}