Get List items using Camel Query with REST API SharePoint
var qry = "";
fPath = "/odp/TradeFunds/Lists/" + lstName + "/" + retail + "/" + fYear;
qry = "<Query><Where><Eq><FieldRef Name='AccountDocumentType' /><Value Type='LookUp'>" + subFolderName + "</Value></Eq></Where></Query>";
var lstNameFromat = "'" + lstName + "'";
var url = _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/GetByTitle(" + lstNameFromat + ")/getItems";
var camlQuery = {
'query': {
'__metadata': {
'type': 'SP.CamlQuery'
},
'ViewXml': '<View>' + qry + '</View>',
'FolderServerRelativeUrl': fPath,
}
};
var option = "";
$.ajax({
url: url,
type: "POST",
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
},
data: JSON.stringify(camlQuery),
success: function(data) {
var olistData = data.d.results;
$.each(olistData, function(i, j) {
var Title = j.Title;
var Guid = j.ItemGuid;
var id = j.ID;
var IdValue = Guid + ";#" + id;
option += '<option value="' + IdValue + '">' + Title + '</option>';
});
$('#ddlSourceItems').empty()
$('#ddlSourceItems').append(option);
},
error: function(data) {
//alert(data.responseText);
}
});
fPath = "/odp/TradeFunds/Lists/" + lstName + "/" + retail + "/" + fYear;
qry = "<Query><Where><Eq><FieldRef Name='AccountDocumentType' /><Value Type='LookUp'>" + subFolderName + "</Value></Eq></Where></Query>";
var lstNameFromat = "'" + lstName + "'";
var url = _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/GetByTitle(" + lstNameFromat + ")/getItems";
var camlQuery = {
'query': {
'__metadata': {
'type': 'SP.CamlQuery'
},
'ViewXml': '<View>' + qry + '</View>',
'FolderServerRelativeUrl': fPath,
}
};
var option = "";
$.ajax({
url: url,
type: "POST",
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
},
data: JSON.stringify(camlQuery),
success: function(data) {
var olistData = data.d.results;
$.each(olistData, function(i, j) {
var Title = j.Title;
var Guid = j.ItemGuid;
var id = j.ID;
var IdValue = Guid + ";#" + id;
option += '<option value="' + IdValue + '">' + Title + '</option>';
});
$('#ddlSourceItems').empty()
$('#ddlSourceItems').append(option);
},
error: function(data) {
//alert(data.responseText);
}
});
Comments