I have been trying to work on this for a few hours and a lot of googling. New to caml queries I simply want to search my list where the variable matches in the column.
In sql I would write:
sql= SELECT COL1 FROM Table WHERE COL1 = '"+ VAR1 +"';
I am trying to retrieve the ID of the result.
function GetProdIDbyName(){
var siteUrl = _spPageContextInfo.webAbsoluteUrl;
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('MyListName');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><Eq><FieldRef Name='Prod_x0020_Name' /><Value Type='Text'>" + ProdName + "</Value></Eq></Query></View>");
this.collListItem = oList.getItems(camlQuery)
clientContext.load(collListItem);
clientContext.executeQueryAsync(ProdIDSucceeded, ProdIDFailed);
}
function ProdIDSucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nID: ' + oListItem.get_id() +
'\nProd Value: ' + oListItem.get_item('Product_x0020_No');
}
alert(listItemInfo.toString());
}
function ProdIDFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
But my results ignore the variable "ProdName" and returns all data in the column. I read this is an issue with the caml string.
Some advice and guidance would be much appreciated. Thank you.