adding more than one list item into List at a time when the items are generated dynamically (using NAPA)
Pergunta
I am using the below code to insert an item into the list.
function createitem() {
var selectListBox = document.getElementById("txtFormName");
var selectedListTitle = selectListBox.value;
var selectedList = web.get_lists().getByTitle(selectedListTitle);
var listItemCreationInfo = new SP.ListItemCreationInformation();
var newItem = selectedList.addItem(listItemCreationInfo);
newItem.set_item('Title','abc');
newItem.update();
context.load(newItem);
context.executeQueryAsync(onItemCreationSuccess, onItemCreationFail);
}
Its working fine. Now I want to use
newItem.set_item('Title1','def');
newItem.set_item('Title2','xyz');
.
.
.
and so on
in loop for more than one item in the same row to insert. How can i achieve that. kindly guide.
Solução
You can use a loop as follows
var selectListBox = document.getElementById("txtFormName");
var selectedListTitle = selectListBox.value;
var selectedList = web.get_lists().getByTitle(selectedListTitle);
for(var index = 0; index < 10; index++) {
var listItemCreationInfo = new SP.ListItemCreationInformation();
var newItem = selectedList.addItem(listItemCreationInfo);
newItem.set_item('Title' + index.toString(),'abc'+ index.toString());
newItem.update();
}
context.load(selectedList);
context.executeQueryAsync(onItemCreationSuccess, onItemCreationFail);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange