Need help with expand - Lookup fields (@pnp/sp/items)

Copper Contributor

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

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.

Hi @Rajashekhar Sheelvant 

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?

 

 

@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.

@Rajashekhar Sheelvant , thank you. We have thought about this as last resort, as we would prefer a more simplified solution without use of Flow, tweak and workload for this type of simple data extract.

 

Hope there is other ways, considering performance issues and solution maintenance. Thanks!