4

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!

1 Answer 1

5

You should use the Internal Name of the column, so its probably:

Link_x0020_to_x0020_Page

Easy way to check the internal name is from the url when you edit the column, and check the "Field=" part of the URL:

FldEdit.aspx?List=%7B6045095F%2DC5AF%2D47D5%2DA481%2D27665B46E343%7D&Field=Link%5Fx0020%5Fto%5Fx0020%5FPage

Replace %5F with underscore, or just paste the url into a url decoder tool

1
  • I was going to mention in my question that I had a suspicion that it might be the whitespace causing the problem. I will try this out and get back, thanks.
    – Alex
    Commented Feb 28, 2013 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.