3

i want to create new event in SharePoint calendar list in which I have some custom columns,i tried below code but it is not working

    function bookingRoomForMeeting() {
        var ctx = new SP.ClientContext(appWebUrl);//Get the SharePoint Context object based upon the URL  
        var list = ctx.get_web().get_lists().getByTitle("MyCalendarList"); //Get the List based upon the Title
        var listCreationInformation = new SP.ListItemCreationInformation(); //Object for creating Item in the List
        listItem = list.addItem(listCreationInformation);
        listItem.set_item('Title', $("#txt_Title").val());
        var date = $("#txt_startTime").val();
        var dateTime = moment(date, 'DD/MM/YYYY HH:mm a').format("MM/DD/YYYY HH:mm a");
        listItem.set_item('EventDate', dateTime);
        var enddate = $("#txt_endTime").val();
        var enddateTime = moment(enddate, 'DD/MM/YYYY HH:mm a').format("MM/DD/YYYY HH:mm a");
        listItem.set_item('EndDate', enddateTime);
        listItem.set_item('EmailId1', $("#txt_EmailId1").val());
        listItem.set_item('EmailId2', $("#txt_EmailId2").val());
        listItem.update();
        ctx.load(listItem);
        ctx.executeQueryAsync(
            Function.createDelegate(this, success),
            Function.createDelegate(this, fail)
           );
    }
function success() {
    alert("Completed");
}
function fail() {
    alert("operation failed");
}

list am using is SharePoint hosted app list,can any one tell me where am going wrong?

Madhav
  • 1,494
  • 1
  • 16
  • 26

1 Answers1

5

Make sure to use internal names of the fields rather than the display name. Change Start Time to EventDate and End Time to EndDate. See Finding the internal name and display name for a list column for more information on internal field names.

Nadeem Yousuf-AIS
  • 18,707
  • 4
  • 28
  • 59
  • the answer helped me to create event in SharePoint calendar list but it is taking and saves default servers time rather am passing,means suppose am passing 08/26/2016 12:00 an am expecting the same to got added in list but it saves default time instead of 12:00,so do you have any idea regarding this? – Madhav Aug 26 '16 at 04:22
  • @Ma6139735, you should ask a new question for this. Include your code in the question. – Nadeem Yousuf-AIS Aug 26 '16 at 05:20
  • yes i did that,http://sharepoint.stackexchange.com/questions/191877/custom-time-value-is-not-getting-saved-in-sharepoint-calendar-list-using-javascr – Madhav Aug 26 '16 at 05:23