1

We have a column defined on a custom list that allows for multiple select of values from another custom list. The column on the list is call Panels. When I do a REST call against this list, I can see the following:

"PanelsId":{"__metadata":{"type":"Collection(Edm.Int32)"},"results":[2,8]}

The numbers 2 and 8 correspond appropriately to the other look up list. But is there a way that I can query the primary list for only the rows that contain the number 2 in the PanelsId field?

3

As Pete M mentioned above you cannot filter directly on a multi-value lookup. The workaround to this is to use a CAML query via an HTTP POST. This does have the overhead of having to get the request digest, if the list doesn't have a large number of items, it may be best just to use client side filtering.

var endPoint = "http://yourdomain/_api/web/Lists/GetByTitle('<your list title>')/GetItems"
var caml = "<View>";
    caml +=   "<Query>";
    caml +=      "<Where>";
    caml +=          "<Eq>";
    caml +=              "<FieldRef Name=\"MultiLookupFieldName\" LookupId=\"TRUE\"/>";
    caml +=              "<Value Type=\"LookupMulti\">"
    caml +=                 id;
    caml +=              "</Value>";
    caml +=           "</Eq>"
    caml +=        "</Where>";
    caml +=      "</Query>";
    caml += "</View>";

var requestData = { "query" :
           {"__metadata": 
              { "type": "SP.CamlQuery" }
              , "ViewXml": caml
           }
        };

$.ajax({
        url: endpoint,
        method: "POST",
        data: requestData,
        headers: {
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "Accept": "application/json; odata=verbose",
            "Content-Type": "application/json; odata=verbose"
        }
    });
  • I am getting ID instead of actual multiselect value. Any idea ? – Sid Nov 25 '17 at 13:12
  • Do you mean in the returned results? Are you using $expand in the query string? – Robert Kaucher Nov 25 '17 at 16:46
  • I guess i got my answer. It is not possible to combine REST and CAML. I have the same issue described here sharepoint.stackexchange.com/questions/136482/… To answer your question yes i tried using $expand and got this error "The $expand query is not valid for field 'Author'." and same error text just replacing Author with MultiSelectColumnName. – Sid Nov 26 '17 at 4:55
  • It appears as though I actually new that at one point... sharepoint.stackexchange.com/questions/166501/… – Robert Kaucher Nov 27 '17 at 18:41
1

Even though query multi-value lookup fields is not supported as were mentioned in another answers, i assume the OP is asking about filtering by multi-value lookup fields.

The following examples demonstrates how to filter by multi-value lookup fields:

Assume a Projects list that contains Tasks multi-value lookup field:

Title        Tasks
Project A    2;8
Project B    2
Project C

Example 1

The query:

/_api/web/lists/getbytitle('Projects')/items?$filter=TasksId eq 2

will return items:

Project A    2;8
Project B    2   

Example 2

The query:

/_api/web/lists/getbytitle('Projects')/items?$filter=TasksId eq 2 and TasksId ne 8

will return items:

Project B    2
  • This is exactly what I want but I get no results no matter what value I put in. – jkandiko Feb 23 '15 at 15:19
  • Hm.. is it SharePoint 2013 on-premises or online? – Vadim Gremyachev Feb 23 '15 at 15:25
  • This solution will not work for SP on-prem, unfortunately. – Robert Kaucher Feb 23 '15 at 16:44
  • @RobertKaucher Yeah, that's what I found out. Too bad though. Was easier to implement than the CAML query, but the CAML query does work. – jkandiko Feb 23 '15 at 18:24
  • 1
    Worked well for me in SharePoint Online..Instead of searching by lookup value , here we are searching by lookup id – Abdul Hameed Jan 25 at 10:35
0

I feel your pain, but unfortunately this is not supported:

https://msdn.microsoft.com/en-us/library/office/fp142385.aspx#sectionSection4

Because multi-value lookup fields are returned as a string of multiple values, there is no way to query for them (for example, the equivalent of an Includes element or NotIncludes element is not supported).

0

Vadim Gremyachev's answer worked for me. If the column name contains camel case then insert "/" before the case change. For example if the column name is "TasksID" then in the query put it as "Tasks/ID" and it will work fine. If "/" is not placed then you will get the following error.

{
"error":{
"code": "-0000234234, System.ArgumentException",
"message":{
"lang": "en-US",
"value": "Column 'TasksID' does not exist. It may have been deleted by another user. "
}
}
}
0

I saw some reference here that multi-value lookup is not possible https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/use-odata-query-operations-in-sharepoint-rest-requests#sectionSection4

But when I tried same to filter post category in SharePoint online blog site it's working.

https://name.sharepoint.com/sites/<sitecllection>/<site>/_api/web/lists/getbytitle('Posts')/items?$select=Id,Title,Body,LikesCount,LikedBy/Title,LikedBy/Id,PostCategory/Title&$expand=LikedBy,PostCategory&$filter=PostCategory/Title eq '<filter value>'

Note: Question is for 2013 SharePoint, I tested in SharePoint online and posted here only for reference, might help other

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.