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.
6
  • 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 Nov 4, 2014 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. Nov 4, 2014 at 12:45
  • Project Phase might be the display name, but not the internal name Nov 4, 2014 at 12:47
  • 2
    Go to list settings and hover mouse over "Project Phase" and check the URL query string "Field=..." Nov 4, 2014 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? Nov 4, 2014 at 12:51

1 Answer 1

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());
}
3
  • Now getting the message Request failed. Column 'Project_x0020_Manager' does not exist. This field is a people picker field. Nov 4, 2014 at 12:57
  • @ThomasLindauer check the internal name by checking the list settings.. then replace it with what you see in the URL Nov 4, 2014 at 12:58
  • Upvoting because you show how to pull properties with spaces in them.
    – jpaugh
    Jul 14, 2017 at 19:31

Your Answer

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

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