1
function fetchProjectData(projectName, callbackOnSuccess) {

    var clientContext = new SP.ClientContext("path to site");
    var oList = clientContext.get_web().get_lists().getByTitle('Project Overview');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'Title\'/>' + 
        '<Value Type=\'Text\'>'+projectName+'</Value></Geq></Where></Query><RowLimit>1</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem, 'Include(Project Phase, Project Manager, Start Date, End Date)');

function onQuerySucceeded(sender, args) {

    var listItemInfo = '';

    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();

        var itemObject = {
            title: oListItem.get_item('Start Date')
        };
        callbackOnSuccess(itemObject);
    }

}

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

    clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));        
}

I'm trying to retrieve data from a list element.

Code above returns the error:

Request failed. Column 'Project Phase' does not exist. It may have been deleted by another user. /projects/Lists/Project Overview

  • This column exists.
  • Project Phase is the internal name.
  • It hasn't been renamed.
  • Its a choice column.
  • You should use the Internal Name of the columns, not the display name. Internal names can not contain blanks so that can not be the correct internal name – Robert Lindgren Nov 4 '14 at 12:44
  • @RobertLindgren I am, Project Phase is the internal name. I made the column myself, I've also retrieved all internal names for that list and Project Phase pops up. – Thomas Lindauer Nov 4 '14 at 12:45
  • Project Phase might be the display name, but not the internal name – Robert Lindgren Nov 4 '14 at 12:47
  • 2
    Go to list settings and hover mouse over "Project Phase" and check the URL query string "Field=..." – Amal Hashim Nov 4 '14 at 12:48
  • @AmalHashim Did this, shows me the XSL version: "Project_x0020_Phase". Where am i to specify this? In the include string at load or in the success function? Maybe both? – Thomas Lindauer Nov 4 '14 at 12:51
2

Try this

function fetchProjectData(projectName, callbackOnSuccess) {
    var clientContext = new SP.ClientContext("path to site");
    var oList = clientContext.get_web().get_lists().getByTitle('Project Overview');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'Title\'/>' + 
        '<Value Type=\'Text\'>'+projectName+'</Value></Geq></Where></Query><RowLimit>1</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem, 'Include(Project_x0020_Phase, Project_x0020_Manager, Start_x0020_Date, End_x0020_Date)');
    clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
}

function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        var itemObject = {
            title: oListItem.get_item('Start_x0020_Date')
        };
        callbackOnSuccess(itemObject);
    }
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
  • Now getting the message Request failed. Column 'Project_x0020_Manager' does not exist. This field is a people picker field. – Thomas Lindauer Nov 4 '14 at 12:57
  • @ThomasLindauer check the internal name by checking the list settings.. then replace it with what you see in the URL – Amal Hashim Nov 4 '14 at 12:58
  • Upvoting because you show how to pull properties with spaces in them. – jpaugh Jul 14 '17 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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