question

SharonChoong-7288 avatar image
0 Votes"
SharonChoong-7288 asked saldana-msft edited

Get Multiple Lookup field for a ListItem in Microsoft Graph API

I have a lookup column in Sharepoint Online that allows multiple values per item. I use the Microsoft Graph .NET SDK to retrieve all the column values for a list item:

 ListItem item = await graphClient.Sites[siteId].Drive.Items[itemId].ListItem.Fields.Request().GetAsync();

I also tried to retrieve the multiple lookup column specifically:

 var queryOptions = new List<QueryOption>()
 {
    new QueryOption("expand", "fields(select=MultipleLookupColumn)"))
 };
 ListItem item = await graphClient.Sites[siteId].Drive.Items[itemId].ListItem.Request(queryOptions).GetAsync();

It correctly shows the column values, including custom columns, except for the multiple lookup column. The lookup column shows up in item.Fields.AdditionalData, but it is always an empty array, even when there are values assigned to it on Sharepoint Online. But if I change the lookup column to disallow multiple values, it shows the value correctly.

So I tried to send an HTTP GET request to see if it is an issue with the SDK. Unfortunately, the resulting JSON also shows an empty array, which means that it is an issue with the Graph API itself. For example, with the column MultiLookup:

 "fields": {
                 "@odata.etag": "\"acf66f85-cc5e-4dcf-a276-e4e5edf5e758,21\"",
                 "FileLeafRef": "file.pdf",
                 "MultiLookup": [],
                 "MultiLookup_x003a_Created": [],
                 "id": "31",
                 "ContentType": "Document",
                 "Created": "2021-05-31T19:43:03Z",
                 "AuthorLookupId": "10",
                 "Modified": "2021-06-02T13:06:52Z",
                 "EditorLookupId": "12",
                 "_CheckinComment": "",
                 "LinkFilenameNoMenu": "file.pdf",
                 "LinkFilename": "file.pdf",
                 "DocIcon": "pdf",
                 "FileSizeDisplay": "31151",
                 "ItemChildCount": "0",
                 "FolderChildCount": "0",
                 "_ComplianceFlags": "",
                 "_ComplianceTag": "",
                 "_ComplianceTagWrittenTime": "",
                 "_ComplianceTagUserId": "",
                 "_CommentCount": "",
                 "_LikeCount": "",
                 "_DisplayName": "",
                 "AppAuthorLookupId": "12",
                 "Edit": "0",
                 "_UIVersionString": "21.0",
                 "ParentVersionStringLookupId": "31",
                 "ParentLeafNameLookupId": "31"
             }

To make sure that it is a bug specific to the Graph API, I also tried getting the lookup values from the old Sharepoint REST API:

 https://{site_url}/_api/Web/Lists(guid'{guid_id}')/Items({item_id})

With the old Sharepoint REST API, I was able to get the lookup values, although the column is called MultiLookupId instead of MultiLookup.

<d:MultiLookupId m:type="Collection(Edm.Int32)"><d:element>5</d:element><d:element>10</d:element><d:element>11</d:element></d:MultiLookupId>

Unfortunately, the old REST API only works on my browser when I am signed in. When I tried to call the old API programmatically with the same access token that I use for Microsoft Graph API, I get an Unauthorized (401) error.

At this point, I am fairly certain that this is a bug in the Microsoft Graph API. Is this an easy fix for the Microsoft dev team, or there another way I can retrieve the multi-lookup column values?








office-sharepoint-onlinemicrosoft-graph-filesmicrosoft-graph-sites-lists
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SharonChoong-7288 avatar image
0 Votes"
SharonChoong-7288 answered

Hi @MichaelHan-MSFT, thanks for your attempt.

I found that it is a permissions issue. I had set up my app with the Files.ReadWrite.All permission, which is sufficient for reading the document library and files in Sharepoint Online, including lookup columns with single values. But unfortunately not lookup columns with multiple values. Once I added Sites.Read.All to permissions, the multiple lookup values array was no longer empty. I believe this is undocumented.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered MichaelHan-MSFT edited

Hi @SharonChoong-7288,

Per my test, I could get the Multiple Lookup field for a ListItem on my end. Below is my test result:

         var fieldValueSet = await graphClient.Sites[siteID].Drive.Items[itemID].ListItem.Fields
                              .Request()
                              .GetAsync();
         var value=new Object();
         if (fieldValueSet.AdditionalData.TryGetValue("MultiLookup", out value))
         {
             Console.WriteLine(value);
         }

101931-image.png

101941-image.png

And in Graph Explorer:

101790-image.png


Besides, we could use this endpoint to get the list item directly: https://docs.microsoft.com/en-us/graph/api/listitem-get?view=graph-rest-1.0&tabs=csharp


image.png (60.1 KiB)
image.png (21.4 KiB)
image.png (64.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.