As I am new to SharePoint framework, I am using PnP JS core library in SharePoint webpart,please suggest how can I retrieve list items from SharePoint list via PnP JS core and CAML Query.
Please suggest any workaround for the same.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityAs I am new to SharePoint framework, I am using PnP JS core library in SharePoint webpart,please suggest how can I retrieve list items from SharePoint list via PnP JS core and CAML Query.
Please suggest any workaround for the same.
You can get items from SharePoint list using a CAML Query.
Sample Code:
import { ICamlQuery } from "@pnp/sp/lists";
// build the caml query object (in this example, we include Title field and limit rows to 5)
const caml: ICamlQuery = {
ViewXml: "<View><ViewFields><FieldRef Name='Title' /></ViewFields><RowLimit>5</RowLimit></View>",
};
// get list items
const r = await list.getItemsByCAMLQuery(caml);
// log resulting array to console
console.log(r);
References: