Question

I have one list with lookup column #lookupColOne and this value is used in #list2.

#List2 have a lookup column of #List1 ID field. I want to get #list2 data along with #list1 lookup column values.

Anyone suggest the idea to achieve this?

Was it helpful?

Solution

You can use your RESTful URL something like below:

/_api/web/lists/GetByTitle('<Display name of #List2>')/items?$select=Title,Country/ID,Country/Title&$expand=Country

Where,

  1. Country: Lookup column in #List2 which is referencing data in #List1.
  2. Country/ID and Country/Title: Gives the ID and Title for selected Item from #List1.

Note:

If you are trying to get the lookup column data from two or more levels of lookup columns then it is not supported in SharePoint REST API. Read more about it here.

OTHER TIPS

following snippet should help you a lot. It expands data from List2 with the information from lookUp in List1

this.web.lists.getByTitle('LIST2NAME').items.select(['Column','Column/Id']).expand('Column').get().then(result => {
          return result 
});

You can achieve this using select and expand.

Here is the sample REST URL.

_api/web/lists/GetByTitle('ListName')/items$select=ColumnNamein#list2/ColumnNamein#list1&$expand=ColumnNamein#list2

You can only get the IMMEDIATE lookup values in rest api. The workaround would be to extend your 2nd lookup in list1 and get all the values you want (which will be added to list1 as text fields). You can get these values using Rest on lookup of list2

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top