0

I am trying to retrieve items from a List, using CAML+RESTApi but when I try to $filter for a lookup column with multiple values it shows me:

{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The expression 'KeyCompetency/ID' is not supported or its usage is invalid."}}}

Below is my code:

function createFilterQuery2() {
var path = var path = globalVariables.appweburl + "/_api/SP.AppContextSite(@target)/Web/Lists/GetByTitle('" + listName + "')/getitems?" +
            "$top=5000" +
            "&$filter=" + query +
            //"&$expand=KeyCompetency"+
            "&$select=*" +
            "&@target='" + globalVariables.hostweburl + "'";

var query = "ServiceLine eq '" + $('#drp_productLine :selected').text() + "'";
var keyCompQuery = "";
        if ($('#drp_keyCompetency :selected').length > 0) {
            $('#drp_keyCompetency > option:selected').each(function (i, e) {
                if (i == 0) {
                    keyCompQuery += "KeyCompetency/ID eq " + $(this).val();
                }
                else {
                    keyCompQuery += " or KeyCompetency/ID eq " + $(this).val();
                }
            });
            query += " and (" + keyCompQuery + ")";
var viewName="first5000";
           PeopleCompetency.getListItemsWithQuery2(path,viewName).done(function (result) {
                dataCollection = $.merge(dataCollection, result);
            }).fail(function (error) {
                console.log("getListItemsWithQuery() : " + error.message);
            });
        }
    }
function getListItemsWithQuery(path,viewName){
try {
            var dfd = $.Deferred();
            var viewXml = '<View><Query><Where><Eq><FieldRef Name="ItemIdentifier" /><Value Type="Text">' + viewName + '</Value></Eq></Where></Query></View>';

            var queryPayload = {
                'query': {
                    '__metadata': { 'type': 'SP.CamlQuery' },
                    'ViewXml': viewXml
                }
            };
            $.ajax({
                url: path,
                type: "POST",
                headers: {
                    "Accept": "application/json;odata=verbose",
                    "Content-Type": "application/json;odata=verbose",
                    "X-RequestDigest": $("#__REQUESTDIGEST").val()
                },
                data: JSON.stringify(queryPayload),
                beforeSend: function () { },
                success: function (data) {
                    var results = data.d.results;
                    dfd.resolve(results);
                },
                error: function (error) {
                    dfd.reject(error);
                    console.log("getListItemsWithQuery() : " + error.message);
                }
            });
        } catch (err) {
            console.log("getListItemsWithQuery() : " + err.message);
        }
        return dfd;
}

I have gone through this, it works but I have to use the above post method only with CAML.

Your Answer

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

Browse other questions tagged or ask your own question.