0

We have custom solution which read lookup list contains more than 5000K items in SharePoint list. Due the list threshold, we can only retrieve the items up to 5000K. This the code that we used. I just wondering is there any a solution to get more than 5000K items

public async getLookups(fieldSchema: any, webUrl: string): Promise<any[]> {
    const url = `${webUrl}/_api/Web/lists/getbyid('${fieldSchema.LookupListId}')/items?$orderby=${fieldSchema.LookupFieldName}&$top=5000`;
try {
    let resp: SPHttpClientResponse = await this.spHttpClient.get(url, SPHttpClient.configurations.v1);
    if (resp.ok) {
        let json = await resp.json();
        return json.value.map((x) =&gt; {
            return { LookupId: x.ID, LookupValue: x[fieldSchema.LookupFieldName], x };
        });
    }
}
catch (error) {
    console.error(error);
}
return [];

}

Supermode
  • 1,799
  • 2
  • 16
  • 33

2 Answers2

1

You can use PnPJs utility, there you can use getAll method in which threshold limit is already handled.

See documentation below

Kalpesh Vaghela
  • 2,215
  • 1
  • 12
  • 25
1

If you are working directly against the API. You can use the data.d.__next property, if there are more results than those 5000, that property will be populated with a url which you have to query to get the next page of results. Do that in a loop until you've got all the results.

This has been solved here: SharePoint REST API read large list items with pagination

Vertamin
  • 186
  • 7