src/util/sp/deleteItem.js
/**
* Deletes an item from a list.
*
* @param {string} list Name of the list to delete from
* @param {string} id Id of the item to delete
*
* @return {Promise<number>} id of deleted item.
*/
export default function deleteItem(list, id) {
return new Promise(function(resolve, reject) {
window.SP.SOD.executeFunc('sp.js', 'SP.ClientContext', () => {
const ctx = window.SP.ClientContext.get_current();
const path = `${window._spPageContextInfo.webAbsoluteUrl}/Lists/${list}`;
const item = ctx.get_web().getList(path).getItemById(id);
ctx.load(item);
ctx.executeQueryAsync(
function(){
item.deleteObject();
ctx.executeQueryAsync(
function(){
resolve(id);
},
function(){reject(arguments);}
);
},
function(){reject(arguments);}
);
});
});
}