SharePoint 2013 REST How to $filter field1 eq field2 (not field eq constantValue)?
16,259
only way that call two diffrent uri two times and then by using loop and variables in javascript do that action you need , like below code :
NEED EDIT FOR CALL
$(function (){loadRequest("/_api//web/GetFolderByServerRelativeUrl('/PublishingImages/wodSlider')/files",
function (data) {
var wodsliderData = data.d.results;
var viewXml = '<View Scope="RecursiveAll"><Query><Where><Eq><FieldRef Name="FSObjType" /><Value Type="Integer">1</Value></Eq></Where></Query></View>';
var array2 = [];
array2=getListItems(webUrl,listTitle,viewXml);
var html='';
if(wodsliderData.length!=0){
for(i=0;i<wodsliderData.length;i++){
for(j=0;j<array2.length;j++){
//............. your code here
}
}
}
$('#wodSliderHtml').html(html);
});
});
function getListItems(webUrl,listTitle, viewXml)
{
var url = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems";
var queryPayload = {
'query' : {
'__metadata': { 'type': 'SP.CamlQuery' },
'ViewXml' : viewXml
}
};
return $.ajax({
url: url,
method: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(queryPayload),
headers: {
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"Accept": "application/json; odata=verbose"
}
});
}
Author by
frevd
Updated on June 04, 2022Comments
-
frevd almost 2 years
Am I missing something or is it really impossible to use SharePoint REST API to filter a list based on the contents of a field and another field?
Constant values work:
?$select=Title&$filter=Title eq 'Hello world'
or
?$select=Title&$filter='Hello world' eq Title
but not
?$select=Title&$filter=Title eq Title
nor
?$select=Title&$filter=Title eq OtherField
nor
?$select=Title&$filter=substringof(Title, Title)
With filtering that limited, REST is practically useless.
Is there some way to use variables or refer to other fields?
EDIT: I just checked, apparently it is a limitation in the SharePoint. It also does not work using CAML, apparently all comparisons have to be Field to ConstantValue.
Doesn't work either:
<Query> <Where><Eq><FieldRef Name="Title" /><FieldRef Name="Title" /></Eq></Where> </Query>
Any idea how to work around this issue? Lookups, Joins? In REST? Thanks.