JSON - Add 5k Items into SharePoint list -Script Editor Webpart
<button onclick="CreateListItem();" type="button">Click me</button>
<script src="https://code.jquery.com/
jquery-2.2.4.js" type="text/javascript"></scrip t> <script type="text/javascript" src="/_layouts/15/sp.runtime.
js"></script> <script type="text/javascript" src="/_layouts/15/sp.js"></scr
ipt>
<script type="text/javascript">
function CreateListItem() {
try
{
// var clientContext = new SP.ClientContext("http://
MyServer/sites/SiteCollection" ); var clientContext = new SP.ClientContext();
var oWeb = clientContext.get_web();
// Specify list title here
var oList = oWeb.get_lists().getByTitle("
Employee");
// Get Item using CAML Query
var camlQuery = new SP.CamlQuery();
// New "ListItemCreationInformation" Object
// Set value for each column here
//oListItem.set_item('Title', 'New item value');
//oListItem.set_item('Notes', 'This is dummy data');
for (var i = 0; i < 5000; i++) {
var oListItemCreationInformation = new SP.
ListItemCreationInformation(); var item = oList.addItem(
oListItemCreationInformation); item.set_item("Name", "Test Title " + i);
if (i < 20) {
item.set_item("Age", 25);
item.set_item("Salary", 25000 + i);
}
else if (i > 20 && i < 100) {
item.set_item("Age", 30);
item.set_item("Salary", 25000 + i);
}
else {
item.set_item("Age", 35);
item.set_item("Salary", 25000 + i);
}
item.set_item("Office", "Office " + i);
item.set_item("Position", "Position " + i);
item.set_item("Title", "Title " + i);
item["StartDate"] = Date.now();
item.update();
clientContext.load(item);
// Execute the query to the server.
clientContext.
executeQueryAsync(onsuccess, onfailed); }
}
catch (ex) {
console.log(ex.message);
}
}
function onsuccess() {
// console.log("Success");
}
function onfailed(sender, args) {
console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
ReplyForward Add reaction |
No comments:
Post a Comment