Introduction

In this article, we will learn how to delete a basic SharePoint-hosted SharePoint Add-in by using Napa Office 365 Development Tools. Sharepoint basic operations are used by JavaScript Object Model here. If there are any changes, post your comments here.

Develop the project using the following method in NAPA Tool.

Prerequisite

The following are important steps to be done before creating the app.

Basic and important things we want to know ,

Creating, updating, and deleting lists through the Client Object Model works similar to the Server Object Model using .NET Framework (CSOM,SSOM), but the operations do not complete until you call the executeQueryAsync (succeededCallback, failedCallback) function.

SharePoint 2013 introduces a NAPA tool service that is comparable with the existing SharePoint Client Object Models. We can use NAPA Tool to perform Create, Read, Update, and Delete (CRUD) operations from their apps for SharePoint.

By following this article, you can learn how to create a simple SharePoint-hosted SharePoint Add-in by using Napa. The add-in that you’ll create includes controls and code for managing lists and list items.

Choose the kind of add-in you want to create, name the project, and then choose the Create button.


Napa is a tool that you can use to create SharePoint-hosted SharePoint Add-ins.

We can't create a PHA (Provider Hosted APP) using NAPA tool.

Click the Create Button,


Default .aspx display like above the pic and App.Js file like,

You could add more .js files and add code to it instead of to the existing file.


Chane your code based on your requirement here,

Default aspx create Button to start this event,


Change the APP.js file with below code,

Then Click settings page to give permission to this app


Then, publish your app.


Choose the "Click here to launch your add-in in a new window" link.


Click "Trust it" option to deploy your app here. After a few seconds, your login window will popup and ask for your credentials .

Enter your credentials and click OK.




List is deleted successfully.

Here, if you want to delete a list, call the deleteObject() function in your code .

Default aspx page code

  1. <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
  2. <div id="starter"> <input type="text" value="List name here" id="ListOperations"/><button id="createlistbutton">ListOperations</button> <p> Lists
  3. </div></asp:Content>

Source code

  1. 'use strict';
  2. var context = SP.ClientContext.get_current();
  3. var user = context.get_web().get_currentUser();
  4. var web = context.get_web();
  5. var lists = web.get_lists();
  6. var listItemCollection; // This variable is used later when you add list items.
  7. (function () {
  8. // This code runs when the DOM is ready and creates a context object which is
  9. // needed to use the SharePoint object model.
  10. $(document).ready(function () {
  11. $("#createlistbutton").click(function (event) {
  12. DeleteListItem();
  13. event.preventDefault();
  14. });
  15. });
  16. function deleteListItem() {
  17. var oList = web.get_lists().getByTitle('TaskList');
  18. this.ListItem = oList.getItemById(3);
  19. ListItem.set_item('Title', 'NewTask');
  20. ListItem.deleteObject();
  21. clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
  22. }
  23. function onQuerySucceeded() {
  24. alert('Item deleted!');
  25. }function onQueryFailed(sender, args) {
  26. alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  27. }
  28. })();