I have a list in SharePoint Online that has a custom HTML form. The form has the following structure:
Country:
Color:
Type:
(These are in a table/gridview and are repeatable/many) Name: Lastname: Gender: Age:
My goal is to have up to 40 rows in the table/gridview so people can add records and once they hit the save button, an item is to be created for each entry in the row with additional appended information from the Country, Color and Type to be added with each record.
So the end result would be a SharePoint list item created for each row.. ex: Country, Color, Type, Name, Lastname, Gender, Age Country, Color, Type, Name, Lastname, Gender, Age
I can create items using the script below but am trying to figure out how can a loop through all the items in the table/gridview and create an item using the same script for each row that has data in the columns for each row:
<script>
var siteUrl = 'http://example.org';
function createListItem() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Testing1');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', 'My New Item!');
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert('Item created: ' + oListItem.get_id());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script><button onclick="createListItem();">Try it</button>
Any help is appreciated