Hi guys I'm new to SharePoint dev and working on a project to retrieve list items. I have followed the instructions from http://msdn.microsoft.com/en-us/library/office/ee539350(v=office.14).aspx and made sure to add my javascript file in the html source of my content editor but still don't get the expected results. I've looked in my developer console for any errors in my JavaScript but nothing seems wrong. Any advice on this will be great. Thanks.
var siteUrl = '/Lists/My_x0020_Rooms';
SP.SOD.ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
function retrieveListItems() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('My_x0020_Rooms');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><eq>' +
'<FieldRef Name=\'Building\'/><Value Type=\'Choice\'>Headquarters_x0020_Building</Value>' +
'</eq></Where></Query><RowLimit>50</RowLimit></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nBuilding: ' + oList.get_item('Building');
}
alert(listItemInfo.toString());
document.getElementById('queryResults').innerHTML=listItemInfo.toString();
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
_x0020_
in your query. And<eq>
/</eq>
should be<Eq>
/</Eq>
._x0020_
. The url might use %20 instead of the unicode character code.