How to do Microsoft Graph API Filter on Lookup Column in SharePoint List Items?
-
12-01-2021 - |
문제
I am tried to apply Filter on Lookup column using Microsoft graph API filter. But it didn't filter. I have used below api to filter.
https://graph.microsoft.com/v1.0/sites/{sites}/lists/{listname}/items?expand=fields(select=Id,Title,LookUpcolumn)&$filter=Fields/LookUpcolumn eq 'value'.
Any help would be appreciated
Thanks in advance!
해결책
The the following expression demonstrates how to filter by lookup field id:
&filter=fields/<LookupFieldName>LookupId eq '<LookupFieldValue>'
Pay attention to lookup field name format, in Microsoft Graph lookup field value is exposed for Lookup Id by default
Example
Lets assume Employee
list contains Department
lookup field (refers to Department
list), then the following query:
https://graph.microsoft.com/v1.0/sites/root/lists/Employee/items?expand=fields(select=Id,Title,Department)&filter=fields/DepartmentLookupId eq '<deplookupId>'
will return list items filtered by Department
lookup Id value
Update
It seems Graph API does not support to apply filter by lookup value
As a workaround you could consider the following solution to filter by lookup value (requires two requests).
Given the above example
1)first step would be to query Departments
list by Title
and return Id property (which corresponds to DepartmentLookupId
property in Employee
list):
https://graph.microsoft.com/v1.0/sites/root/lists/Department/items?expand=fields(select=Id)&filter=fields/Title eq '<value>'
2) and then to query Employee
list by Department
lookup Id:
https://graph.microsoft.com/v1.0/sites/root/lists/Employee/items?expand=fields(select=Id,Title,Department)&filter=fields/DepartmentLookupId eq '<deplookupId>'