0

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.

Eldrad95
  • 35
  • 5
  • Do you mean the approach with paging is not working for you? https://pnp.github.io/pnpjs/sp/items/#get-paged-items – Nikolay Nov 17 '22 at 16:49
  • I don't need Paging I need to get items from a specific view and do some stuff with so paging would be a problem. – Eldrad95 Nov 17 '22 at 21:22
  • 1
    I see. In your error message, mentioning moment.js looks suspicious - pnpjs (or spfx) do not use moment.js at all, as far as I know. Are you using some polyfill maybe? Your code also looks fine, it's unlikely that the problem is with the code you posted. I'd try putting a breakpoint at the place where the exception happens. – Nikolay Nov 18 '22 at 11:33
  • I have this error on vscode : https://tmpfiles.org/dl/275277/error.png the url : '_api/web/lists/getByTitle('MyList')/views/getByTitle('TestView')?%24select=ViewQuery' – Eldrad95 Nov 18 '22 at 12:45
  • Thanks you so much ! I finally changed my function to set sp const with const sp = spfi().using(SPFx(context)); (where context is webpart context). it changed the url to a full one with domain and now it works. – Eldrad95 Nov 18 '22 at 12:58

1 Answers1

0

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.

Eldrad95
  • 35
  • 5