Pergunta

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.

Foi útil?

Solução

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:

  1. Get list items using a CAML Query
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top