Introduction

In this article, we will learn how to create a field to list the basic SharePoint-hosted SharePoint add-in, 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 method given below in Napa tool.

Prerequisite

Basic and important things, which we want to know are given below.

Creating, updating and deleting the lists through Client Object Model works similarly to Server Object Model, using .NET Framework(CSOM,SSOM), .

The operations do not complete until and unless, you call the executeQueryAsync(succeededCallback, failedCallback) function.

SharePoint 2013 introduces a Napa tool tservice, which is comparable to the existing SharePoint Client Object Models.

With NAPA Tool, we can 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, using Napa. The add-in that you’ll create includes controls and code for managing the lists and list items.

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


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

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

Click Create button.


Default .aspx displays the screenshot given above.

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


Change your code, which is based on your requirement here.

Default aspx create button is there to start this event.


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

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


Publish your app.


Choose Click here to launch your add-in in a new Window link.


Click Trust it option to deploy your app here. Sometimes your login popup Window will come and ask your credentials.

Enter your credentials and then click OK.




List deleted successfully.

Here, if you want to delete a list, call the update();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. AddColumntolist();
  13. event.preventDefault();
  14. });
  15. });
  16. function AddColumntolist() {
  17. var oList = clientContext.get_web().get_lists().getByTitle('Announcements');
  18. this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'NewField\' Type=\'Note\' />', true, SP.AddFieldOptions.defaultValue);
  19. var fieldNumber = clientContext.castTo(oField,SP.FieldNumber);
  20. fieldNumber.set_maximumValue(100);
  21. fieldNumber.set_minimumValue(35);
  22. fieldNumber.update();
  23. clientContext.load(oField);
  24. clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
  25. }
  26. function onQuerySucceeded() {
  27. alert('Column Created!');
  28. }function onQueryFailed(sender, args) {
  29. alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  30. }
  31. })();

Once the code has been executed, go back to Sharepoint site and check whether the list operations executed successfully or not.

Thanks for reading the article.