1) function deleteItem(id) {
//REST.Common.deleteDataFromParentList(customlist.TravelRequestlist, id);
var department = 52;
var customListName = 'TMS_AirBooking';//Custom List Name
var query = '<View><Query><Where><Eq><FieldRef Name=\'Travel_Req_No\'/>' +
'<Value Type=\'Number\'>' + department + '</Value></Eq></Where></Query><RowLimit>10</RowLimit></View>';
var columns = ['Travel_Req_No'];
deleteDataFromChildList(customListName, query, columns);
// alert(id + ',' + 'TravelRequests');
}
2) deleteDataFromChildList: 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();
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
itemArr[counter] = listItem.get_item("ID");
counter++;
}
for (var id in itemArr) {
var spItem = mylist.getItemById(itemArr[id]);
spItem.deleteObject();
}
context.executeQueryAsync(
function () {
alert('success');
},
function () {
error();
});
},
function () {
error();
});
}
}
//REST.Common.deleteDataFromParentList(customlist.TravelRequestlist, id);
var department = 52;
var customListName = 'TMS_AirBooking';//Custom List Name
var query = '<View><Query><Where><Eq><FieldRef Name=\'Travel_Req_No\'/>' +
'<Value Type=\'Number\'>' + department + '</Value></Eq></Where></Query><RowLimit>10</RowLimit></View>';
var columns = ['Travel_Req_No'];
deleteDataFromChildList(customListName, query, columns);
// alert(id + ',' + 'TravelRequests');
}
2) deleteDataFromChildList: 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();
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
itemArr[counter] = listItem.get_item("ID");
counter++;
}
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