In this article, we will cover how to use the PnP JS Core library to create a new view in SharePoint list. To know more about this JavaScript library, check the below links

In this post,

How to create new VIEW in SharePoint List using PnP JavaScript Library.


title: string, 
personalView = false, 
additionalSettings: TypedHash<string | number | boolean> = {}): Promise<ViewAddResult> 
Adds a new view to the SharePoint List based on the specified parameters
ListName - Title of the SharePoint List, where we want to add the view @param1 > title - The new views's title @param2 > personalView - True if this is a personal view, otherwise false, default = false @param3 > additionalSettings - Will be passed as part of the view creation body


The below steps and code snippets used to create a new view in SharePoint list using PnP JavaScript library,

  1. Download Required files to use PnP-JS-Core library from the below links and upload that to Site Asstes or Style Library
    • Download pnp.js PnP JS file
    • Download fetch.js Used by PnP js file to handle web requests and responses (Required in IE)
    • Download promise.js Used by PnP js file to handle web requests and responses (Required in IE)
  2. Create new web part page and insert Content Editor web part
  3. Create a sample.html file in Site Assets or Style library and insert the below code snippet

<script type="text/javascript" src="/siteassets/scripts/fetch.js"></script>
<script type="text/javascript" src="/siteassets/scripts/promise.min.js"></script> 
<script type="text/javascript" src="/siteassets/scripts/pnp.min.js"></script>
<span id="sample"></span>

<script type="text/javascript">  
//The below views.add method creates the view and enables the mobile view & sets this view as a mobile default view
$pnp.sp.web.lists.getByTitle("List Title").views.add('View Name', false, {
    'MobileView': true,
    'MobileDefaultView': true
}).then(function(res) {
    document.getElementById("sample").innerHTML = + " - view created successfully";

Typescript Example:

Typescript is the superset of JavaScript and this PnP JS library is developed using the typescript specification. For developing the SharePoint Framework web parts and make the client side development easier, we can vote for typescript. The below is the typescript example for adding a new view to the SharePoint List.

import pnp from "sp-pnp-js";
pnp.sp.web.lists.getByTitle("List Title").views.add("View Name",false).then((res) =>{
    console.log(`${} created successfully`);
    console.log(`Error: ${err}`)


Our code returns the success message, if the view created successfully for the SharePoint List.

Create a new VIEW in SharePoint List
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *

Total hysterectomy involves removing both the body of the uterus and the cervix, which is the lower part of the uterus. When the lifestyle and the supportive dietary measures are implemented then that can be effective in curing the disease. 3) that spans three genes, namely, fasn, coiled-coil-domain-containing 57 (ccdc57), and solute-carrier family 16, member 3 (slc16a3). laboratorio eli lilly viagra can you buy viagra over counter turkey 3) that spans three genes, namely, fasn, coiled-coil-domain-containing 57 (ccdc57), and solute-carrier family 16, member 3 (slc16a3). The drugs, however, can cause side effects similar to menopausal symptoms such as hot flushes, loss of periods and vaginal dryness. Camargo , p. natural viagra diet The story of the... nbsp our staff is friendly, courteous and respectful. AlamAtildeiexcl , p. Mccloud freelance writer living in ohio, who is striving to learn more each day, especially about topics that relates to health, wellness, diet, weight loss exercise. In most cases, local or regional anesthesia is considered safer than general anesthesia. Vaginal atrophy is inflammation of the vaginal was that occurs with declining estrogen levels. Recurrence of fibroids is rare, though long-term studies of 10 years or more have shown that about 10% of patients may need additional treatment after 10 years.