I'm trying to fetch items from a specific view of a Sharepoint list in SPFX using @pnp/sp library but I'm unable to do so. I'm able to fetch the view properties and fields of the list. I didn't find anything as such to fetch the items of that view. How will I be able to acheive the same and also my list contains Lookup columns as well.
-
There is another similar thread here (sharepoint.stackexchange.com/questions/264455/…)– Mark LJun 8, 2020 at 7:50
1 Answer
Sample test code for your reference.
sp.web.lists.getByTitle('MyDoc2').views.getByTitle("All Documents").get().then((view: any) => {
sp.web.lists.getByTitle('MyDoc2').getItemsByCAMLQuery({
ViewXml: `<View><Query>`+view.ViewQuery+`</Query></View>`
}).then((items: any) => {
console.log(items);
});
})
-
Thankyou for your response. The list has Lookup fields as well so, how do I expand those fields using this method getItemsByCAMLQuery? Jun 8, 2020 at 9:00
-
If the lookup filed displays in your view, you could get the lookup item id as items[i].TestLookupId, TestLookup is the lookup field.– Lee_MSFTJun 8, 2020 at 9:11