0

I'm using the following to read data from a custom list in SharePoint 2013:

var items;


$(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(CustomAction, "sp.js"); });

function CustomAction() {

    var context = SP.ClientContext.get_current();
    var list = context.get_web().get_lists().getByTitle('ChapterTeeContest');
    var camlQuery = SP.CamlQuery.createAllItemsQuery();
    items = list.getItems(camlQuery, 'Total Events');
    context.load(items,'Include(Title,Total Events)');
    context.executeQueryAsync(Function.createDelegate(this, onListDataSucceeded), Function.createDelegate(this, onListDataFailed)); 

    function onListDataSucceeded(sender, args) {
        var listItemEnumerator = items.getEnumerator();
        while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        console.log(oListItem.get_item('Title') + oListItem.get_item('Total Events'));
        }
    }

    function onListDataFailed(sender, args) {
        console.log('List Data fetch failed. ' + args.get_message() + 'n' + args.get_stackTrace());
    }

}

and I have a custom list with 3 columns:

Title, Event Label, Total Events

But for some reason when I run this script I get the following message...

List Data fetch failed. Column 'Total Events' does not exist. It may have been deleted by another user.
  • Maybe try internal name of the column, Total_x0020_Events. Space is replaced with _x0020_ in Internal names.. Otherwise you can go to List settings -> Under columns click Total Events and check the Field name in URL. That is the internal name of the column. – Arsalan Adam Khatri Mar 9 '15 at 19:13
  • dude! I owe you 1000000 points!! thank you!! it was the x0020 that worked! – klewis Mar 9 '15 at 19:19
  • :) No problem.. I will add it as answer so you can accept it to close the Question.. ;) – Arsalan Adam Khatri Mar 9 '15 at 19:21
1

Maybe try internal name of the column, Total_x0020_Events. Space is replaced with _x0020_ in Internal names..

Otherwise you can go to List settings -> Under columns click Total Events and check the Field name in URL. That is the internal name of the column.

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.