Advertisement

Responsive Advertisement

Create New List in SharePoint using PNP JS

The Patterns and Practices JavaScript Core Library was created to help developers by simplifying common operations within SharePoint and the SharePoint Framework. Currently it contains a fluent API for working with the full SharePoint REST API as well as utility and helper functions.
Download pnp.js fromPNP JS

You will need to set up the library to use verbose OData mode. 
This will apply to all request which is sent to server, add below setup before making any request.
Import pnp.js

/siteasstes/scripts/pnp.min.js
$pnp.setup({

      headers: {

"Accept": "application/json; odata=verbose"
       }

});

Code snippet will create a new list in SharePoint site

$pnp.sp.web.lists.add('TestList', 'Description for generic list', 100, false)
.then(function(result) {
   if (result.data.Created)
      alert('List Created Successfully!');
});

Post a Comment

0 Comments