Create A Basic SharePoint-Hosted Add-In By Using "Napa" Office 365 Development Tools

Introduction

In this article, we will learn how to create a basic SharePoint-hosted SharePoint add-in, using "Napa" Office 365 Development Tools.Sharepoint basic operations, which are used by JavaScript object model. If there are any changes, post your comments.

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


Click Create button.


Default .ASPX display, as shown above and App.Js file is shown below.


Change your code, which is based on your requirement.

Default ASPX is required to create a button to start the event.


Change the APP.js file with the code given below.


Now, click settings page to give the permission to this app.


Subsequently, publish your app.




Click Trust it option to deploy your app.




The list is created successfully.

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.   
  3. var context = SP.ClientContext.get_current();  
  4. var user = context.get_web().get_currentUser();  
  5. var web = context.get_web();  
  6. var lists = web.get_lists();  
  7. var listItemCollection;  // This variable is used later when you add list items.  
  8.   
  9. (function () {  
  10.   
  11. // This code runs when the DOM is ready and creates a context object which is   
  12. // needed to use the SharePoint object model.  
  13. $(document).ready(function () {     
  14.       
  15.     $("#createlistbutton").click(function (event) {  
  16.         createlist();  
  17.         event.preventDefault();  
  18.     });  
  19.     });    
  20. function createlist() {  
  21.         // Create a generic SharePoint list with the name that the user specifies.  
  22.         var listCreationInfo = new SP.ListCreationInformation();  
  23.         var listTitle = document.getElementById("ListOperations").value;  
  24.         listCreationInfo.set_title(listTitle);  
  25.         listCreationInfo.set_templateType(SP.ListTemplateType.genericList);  
  26.         lists = web.get_lists();  
  27.         var newList = lists.add(listCreationInfo);  
  28.         context.load(newList);  
  29.         context.executeQueryAsync(onListCreationSuccess, onListCreationFail);  
  30.     }  
  31.     function onListCreationSuccess() {  
  32.          alert('List Created Successfully');  
  33.     }  
  34.     function onListCreationFail(sender, args) {  
  35.         alert('Failed to create the list. ' + args.get_message());  
  36.     }  
  37. })();  
Ebook Download
View all
Learn
View all