Below is some sample code of how to delete a list on the host web from the app web via SharePoint JavaScript object model
function DeleteList(listName) {

    //Using the App Web as the client context
    clientContext = new SP.ClientContext.get_current();

    //Get the host web URL from the query string params
    //I have a function getHostWebUrl() - which is not included.
    //http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
    var hostWebUrl = getHostWebUrl();
    //Using the hostWebContext as an AppContextSite
    hostWebContext = new SP.AppContextSite(clientContext, hostWebUrl);

    //get the list using the host web context
    var list = hostWebContext.get_web().get_lists().getByTitle(listName);
    list.deleteObject();

    //Always use the context of the app web to do the work or load and executing
    clientContext.executeQueryAsync(function() {
        console.log("Deleted List : \"" + listName + "\"");
    }, function(sender, args) {
        console.log("Failed to delete list : " + listName);
        console.log("Reason : " + args.get_message() + "");
    });

}

// parameters : List Name
DeleteList("My Test List");
There are no comments.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.