I am having this weird issue while deleting a list using CSOM. My SharePoint App has 2 buttons - one to create a list and the other to delete the created list.

When the app loads for the first time, list is created & deleted successfully. enter image description here enter image description here

When trying to delete the list again once its created, delete operation fails. enter image description here

On list deletion - enter image description here

Clicking Create button shows that the list does exist. enter image description here

CSOM code to delete the list -

function listDeletion() {

    var list = null;
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle("Tasks");


    context.executeQueryAsync(success, fail);

    function success() {
        var mess = $("#message");
        mess.text("Tasks List deleted successfully");

    function fail(sender,args) {
        var mess = $("#message");
        mess.text("An error occured : "+args.get_message());


Try this:

<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.requestexecutor.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
    SP.SOD.executeFunc('sp.js','SP.ClientContext', listDeletion);

function listDeletion() {
    var clientContext = SP.ClientContext.get_current();
    var web = clientContext.get_web();
    this.list = web.get_lists().getByTitle("Task");
    clientContext.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.onQueryFailed));

function success() {
    var result = 'Task deleted.';

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
| improve this answer | |
  • No. It didn't work. There was an exception - Object doesn't support property or method 'ExecuteQuery' – Thomas Mathew Nov 11 '14 at 11:17
  • Edited, try now – Nk SP Nov 11 '14 at 11:47
  • This is also not working. Gave an exception -JavaScript runtime error: Unable to get property 'apply' of undefined or null reference. I tried Function.createDelegate(this,success), but facing the same issue i posted. – Thomas Mathew Nov 12 '14 at 4:43
  • Edited again. That code is working on my environment – Nk SP Nov 12 '14 at 8:33
  • Thanks for help but this also didn't work.The mentioned scripts are already included. SP.SOD.executeFunc('sp.js','SP.ClientContext', listDeletion) will delete the list for the first as the function is called automatically. But when deleting the second time, it gives the same error. – Thomas Mathew Nov 12 '14 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.