0

I have some experience using the SharePoint Client Object Model to retrieve text fields and URLs/images from lists in SP 2013. I'm currently trying to do something similar with a calendar. I have been able to successfully retrieve Title and Location fields without any issue, but the Start and End Time fields I am not able to retrieve. I cannot figure out what exactly the issue is. Additionally, I can read Created and Modified with no problems. Here is the relevant code:

function retrieveListItemsCal() {
    var clientContextCal = new SP.ClientContext.get_current();
    var oListCal = clientContextCal.get_web().get_lists().getByTitle('Calendar');
    var camlQueryCal = new SP.CamlQuery.createAllItemsQuery();
    AllItemsCal = oListCal.getItems(camlQueryCal);
    clientContextCal.load(AllItemsCal);

    clientContextCal.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededCal), Function.createDelegate(this, this.onQueryFailedCal));
}

function onQuerySucceededCal(sender, args) {
    var listItemInfo = '';
    var listItemEnumeratorCal = AllItemsCal.getEnumerator();

    var htmlCal = '';

    htmlCal+="<div id='CalHeader'>Upcoming Events</div>\
    <div id='CalDivider'></div>\
    <div id='CalContainer'>";

    while(listItemEnumeratorCal.moveNext()) {
        var oListItemCal = listItemEnumeratorCal.get_current();

        /*htmlCal+="<div class='CalItem'>\
                "oListItemCal.get_item('Start Time')"\
            </div>";*/
        alert(oListItemCal.get_item("Start Time").format("MMMM d, yyyy"));
    }
    htmlCal+="</div>";

    $("#CalSpace").append(htmlCal);
}

function onQueryFailedCal(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

$(document).ready(function(){
    SP.SOD.executeFunc("sp.js", "SP.ClientContext", retrieveListItemsCal);
});

And here is a screenshot of the list columns:

screenshot

2

Check you are using the internal name for these columns.

If you created the column 'Start Time' through the SP GUI, the internal name will end up being 'Start_x0020_Time'.

  • Unfortunately this didn't work for me. The Start Time and End Time columns are automatically generated when you create a Calendar app, if it makes a difference. – user18184 Sep 6 '13 at 14:14
0

I have resolved my issue. I ran the following PowerShell queries (found here http://techtrainingnotes.blogspot.com/2012/10/sharepointfinding-column-display-and.html):

$web = Get-SPWeb SiteUrl
$list = $web.Lists["Calendar"]
$list.fields | select Title, InternalName, Hidden, CanBeDeleted | sort title | ft -AutoSize

The internal names of the Start Time and End Time fields are EventDate and EndDate, respectively.

Your Answer

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