I'm trying to query a SharePoint list on my root site collection but keep getting the error "Request failed, cannot complete this action". I messed around with the CAML query below and have figured out that the CAML is the issue, but I'm not sure what the problem is. I know it's the issue because when I remove the clause it queries successfully.
function retrieveListItems() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('ICE Divisions');
console.log(oList);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='internalFieldName'><Value Type='Lookup'>value</Value></FieldRef></Eq></Where><OrderBy><FieldRef Name='internalFieldName'/></OrderBy></Query></View>");
var collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
console.log(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
console.log(oListItem);
}
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
}
}
},
Any ideas?
<FieldRef>
cannot contain any child element like<Value>
. Instead it should be<Eq><FieldRef Name='internalFieldName' /><Value Type='Lookup'>value</Value></Eq>
– Lukas Nespor Jan 11 '19 at 22:58