sharepoint-onlinespfxpnp-js

pnpjs get sharepoint items by view issue


I'm trying to get items from large lists using pnpjs/sp

I created a promise like this:

  try {

// const sp = spfi();
const sp = spfi().using(DefaultInit(), DefaultHeaders(), BrowserFetchWithRetry(), DefaultParse());
const list = sp.web.lists.getByTitle(ListName);
const listView = await list.views.getByTitle(ViewName).select("ViewQuery")();
const xml = '<View><Query>' + listView.ViewQuery + '</Query></View>';
const items = await list.getItemsByCAMLQuery({'ViewXml' : xml});
return items;
}
catch (err){
    console.log(err);
    return undefined;
}

but I can't get listView. I have this error :

TypeError: Failed to construct 'URL': Invalid URL
at Proxy.<anonymous> (telemetry.js:6:31)
at moments.js:54:1
at async queryable.js:101:1

when I put a break point and check for the view url it seems to be good (I can access with website url + view url ). I must do something wrong but I don't find what.


Solution

  • Take a look to the question comment for the answer.

    my issue was to not use the spfi().using correctly :

    spfi().using(SPFx(context))
    

    where context is the webpart Context.