I use spfx in version 1.8.2 and I use @pnp/sp already to fetch views, but this gives me only properities of views, but I need items of list with are visible on sharepoint list in those views.

    .views.getByTitle("BySomething").get().then(v => {

I take it from this site https://github.com/SharePoint/PnP-JS-Core/wiki/Working-With:-Views

So I am looking for help or tips, link how do that?


I am afraid you can't get items directly from view. You will get viewQuery field from below method using v.ViewQuery. then you have to use getItemsByCAMLQuery method to get items. Below are reference methods.

Main method calling resua

public getListViewData():void{
    let listName = "Custom List"; //The display name of the sharepoint list.
    let viewName = "All Items"; //The View Name

    getViewQueryForList(listName,viewName).then((res:any) => {
            items.forEach((item:ISPLists) => {
                this.domElement.innerHTML += item.Title + "<br/>";

//First method that retrieves the View Query
public static getViewQueryForList(listName:string,viewName:string):Promise<any> {
    let listViewData = "";
    if(listName && viewName){
        return pnp.sp.web.lists.getByTitle(listName).views.getByTitle(viewName).select("ViewQuery").get().then(v => {
            return v.ViewQuery;
    } else {
        console.log('Data insufficient!');
        listViewData = "Error";

//Second method that retrieves the View data based on the View Query and List name
public static getItemsByViewQuery(listName:string, query:string):Promise<any> {
    const xml = '<View><Query>' + query + '</Query></View>';  
    return pnp.sp.web.lists.getByTitle(listName).getItemsByCAMLQuery({'ViewXml':xml}).then((res:SPHttpClientResponse) => {
        return res;

Ref link - https://wowsomuch.com/sharepoint/pnp-js-caml-query/

  • Yes, It work exacly as i want :) thanks – Jarosław Wałach Jun 11 at 9:47
  • np..please upvote and mark as answer if was helpful.. – Siddharth Vaghasia Jun 11 at 10:22
  • I marked as anwser but I can't upvote low reputation points – Jarosław Wałach Jun 11 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.