question

NigelWitherdin-1999 avatar image
0 Votes"
NigelWitherdin-1999 asked MichaelHan-MSFT commented

Using get() when retrieving items with PnP JS Core only return "Undefined" - using items() returns values??

First of all, big shout out to the PnP JS guys and gals - great library that I use constantly!

With v2.4.0 I am finding that using the get() call when retrieving items is now returning an "undefined" value, however using the items() call is returning items:

Returns undefined:

 const items: any[] = await sp.web.lists
   .getByTitle("Monthly Reports")
   .items.get();

returns expected values:

 const items: any[] = await sp.web.lists
   .getByTitle("Monthly Reports")
   .items();

Why is this?

I want to use the ".get()" call as I want to also call a number of other modifiers, such as:

 sp.web.lists
   .getByTitle("Monthly Reports")
   .items
   .filter(query)
   .expand("FieldValuesAsText")
   .select(
     "ID",
     "FieldValuesAsText/FileRef",
     "Title"
   )
   .top(5000)
   .orderBy("Modified", false)
   .get()

Any suggestions greatly appreciated!



office-sharepoint-online
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Probably should have shown my pnp setup in the webpart .ts file:

const { sp } = await import(
/ webpackChunkName: 'pnp-sp' /
"@pnp/sp"
);

// init sp pnpjs library
sp.setup(this.context);


Thanks again

0 Votes 0 ·

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered MichaelHan-MSFT commented

Hi @NigelWitherdin-1999,

Per my test, both items.get() and items() works on my end. Below is my code:

 import { sp } from "@pnp/sp/presets/all";


 sp.setup(this.context);
 const items: any[] = await sp.web.lists.getByTitle("List1").items.get();
 console.log(items);


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @NigelWitherdin-1999,

Is there anything update? Have you solved this issue? If my answer is helpful, please click "Accept Answer" and upvote it :)

0 Votes 0 ·