Forum Discussion
Need help with expand - Lookup fields (@pnp/sp/items)
Hi folks,
I have two lists (1. Projects, 2. Schedule). Schedule list include a Lookup Field to Projects List.
We are trying the (ref. https://pnp.github.io/pnpjs/sp/docs/items/) "Retrieving Lookup Fields" according to guidance:
import { sp } from "@pnp/sp"; sp.web.lists.getByTitle("LookupList").items.select("Title", "Lookup/Title", "Lookup/ID").expand("Lookup").get().then((items: any[]) => { console.log(items); });
After implement this code we get issue/error trying to query underling special fields (Choice or Lookup Fields).
sp.web.lists.getByTitle("Vessel%20Schedule").items.select("*, Project/Title, Project/Phase").expand("Project").getAll();
This throw error, it can't read/get the "Phase" choice field value from the underlying Project List.
Appreciate assistance and guidance. Thanks!
4 Replies
- Rajashekhar SheelvantBrass Contributor
Hi gselvag ,
pnpjs is a wrapper js utility for sharepoint REST API and it is not possible to fetch choice field using lookup functionality of REST API. Can you try excluding the choice field and check if your query works.
- gselvagCopper Contributor
Thank you for your feedback. We've tried without the Lookup field and it works fine.
Is there a workaround, on how do we get the lookup value into our list?
- Rajashekhar SheelvantBrass Contributor
gselvag , You may probably store this value in a hidden field. Please do not use calculated column for this but you can use designer workflow or MS flow. and you can try fetching this hidden field using same logic. Not sure how it fits your requirement, but this is one of the option.