deleteDataFromListByQuery: function (customListName, query, columns) {
var scriptbase = hostUrl + "/_layouts/15/";
$.getScript(scriptbase + 'SP.Runtime.js',
function () {
$.getScript(scriptbase + 'SP.js',
function () {
$.getScript(scriptbase + 'SP.RequestExecutor.js', deleteItem);
});
});
function deleteItem() {
var context;
var factory;
var appContextSite;
var mylist;
context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostUrl);
this.web = appContextSite.get_web();
mylist = this.web.get_lists().getByTitle(customListName);//Custom List Name
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(query);
var collListItem = mylist.getItems(camlQuery);
context.load(mylist);
context.load(collListItem);
context.executeQueryAsync(
function () {
var listItemEnumerator = collListItem.getEnumerator();
var counter = 0;
var itemArr = new Array();
var id;
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
//itemArr[counter] = listItem.get_item("ID");
//counter++;
id = listItem.get_item('ID');
var spItem = mylist.getItemById(id);
spItem.deleteObject();
}
// for (var id in itemArr) {
// var spItem = mylist.getItemById(itemArr[id]);
// spItem.deleteObject();
// }
context.executeQueryAsync(
function () {
alert('success');
},
function () {
error();
});
},
function () {
error();
});
}
}
var scriptbase = hostUrl + "/_layouts/15/";
$.getScript(scriptbase + 'SP.Runtime.js',
function () {
$.getScript(scriptbase + 'SP.js',
function () {
$.getScript(scriptbase + 'SP.RequestExecutor.js', deleteItem);
});
});
function deleteItem() {
var context;
var factory;
var appContextSite;
var mylist;
context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostUrl);
this.web = appContextSite.get_web();
mylist = this.web.get_lists().getByTitle(customListName);//Custom List Name
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(query);
var collListItem = mylist.getItems(camlQuery);
context.load(mylist);
context.load(collListItem);
context.executeQueryAsync(
function () {
var listItemEnumerator = collListItem.getEnumerator();
var counter = 0;
var itemArr = new Array();
var id;
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
//itemArr[counter] = listItem.get_item("ID");
//counter++;
id = listItem.get_item('ID');
var spItem = mylist.getItemById(id);
spItem.deleteObject();
}
// for (var id in itemArr) {
// var spItem = mylist.getItemById(itemArr[id]);
// spItem.deleteObject();
// }
context.executeQueryAsync(
function () {
alert('success');
},
function () {
error();
});
},
function () {
error();
});
}
}
No comments:
Post a Comment