In this article, we will cover how to use the PnP JS Core library to get the collection of views from the SharePoint List. To know more about this JavaScript library, check the below links

In this post,

How to get collection of views from List using PnP JavaScript Library.


Returns the collection of views from the list specified in the ListName parameter


The below steps and code snippets used to get a view details from the 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 property returns the collection List Views
$pnp.sp.web.lists.getByTitle("CustomList").views.get().then(function(res) {
 var strHtml = "";
 for (var i = 0; i < res.length; i++) {
 strHtml += "<strong>" + res[i].Title + "</strong><br/>";
 strHtml += "ID: " + res[i].Id + "<br/>";
 strHtml += "URL: " + res[i].ServerRelativeUrl + "<br/>";
 document.getElementById("sample").innerHTML = strHtml;

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 retrieving the list views.

import pnp from "sp-pnp-js";
pnp.sp.web.lists.getByTitle("CustomList").views.get().then((res) => {
 let strHtml: string = "";
 for (let view of res) {
 strHtml += "<strong>" + view.Title + "</strong><br/>";
 strHtml += "ID: " + view.Id + "<br/>";
 strHtml += "URL: " + view.ServerRelativeUrl + "<br/>";
 document.getElementById("sample").innerHTML = strHtml;


All Items
ID: ca0ac4cf-e1b4-4b20-8058-f982c8608152
URL: /Lists/CustomList/AllItems.aspx
My Items
ID: 0f0e622d-3cbd-42fb-a11d-2124152791cf
URL: /Lists/CustomList/MyItems.aspx
Get View collection from SharePoint List
Tagged on:             

Leave a Reply

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

Selvatici , a. When the tube arrives in the uterine artery, the doctor directs it to the branches of the artery that allow blood to flow to the fibroids. From there, a very small nick in the groin area will be made, through which a narrow catheter is inserted. Html 29. viagra lilly cares best time day take daily dose viagra ) to link to this article: copy the html link code shown in the box just below. It is not helpful for large fibroids or for fibroids that have grown outside of the interior uterine lining. Html 29. viagra daily use , is confident hp can recapture the drive and creativity that established the company as an industry leader through most of its 73-year history. They can provide an alternative to a hysterectomy. , 2003). Proc natl acad sci usa. Related news articles survival better for hpv cancers of mouth breast tumors grow faster in younger women high blood sugar increases birth risks accurate mammograms reduce biopsies more... nbsp congratulations to you all! nbsp nbsp report abuse reply quote 10-07-2012 at 9:26 pm danieleand... meaning bathtubs viagra commercials