I am trying to use this method to query items of a column of a list in my SP site via javascript (the reason I am doing this is to display that info on the page by modifying the html tags in the DOM), but I am only able to query the "ID" column of my list, which is a Picture Library. The column I want is actually a Text column titled "Link to Page", but it is throwing the following error
"The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested."
Here are the relevant sections of code that I am using:
function retrieveListItems() {
var newLinks = [];
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('ListName');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><OrderBy><FieldRef Name=\'Link to Page\'/></OrderBy></Query></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
return newLinks;
}
function onQuerySucceeded(sender, args) {
var listItemEnumerator = collListItem.getEnumerator();
var itemCount = collListItem.get_count();
var newLinks = new Array(parseInt(itemCount) - 1);
alert("array length: " + newLinks.length);
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
newLinks[i] = oListItem.get_item('Link to Page');
}
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
$(document).ready(function() {ExecuteOrDelayUntilScriptLoaded(retrieveListItems,"sp.js");});
I thought my problem might be similar to this post but that solution doesn't seem to be working for me. I'd be grateful for any pointers on this!