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?

  • What error are you getting? Also make sure to use internal field names. – Nadeem Yousuf Aug 22 '16 at 6:01
  • it is eexecuting fail() function – Madhav Aug 22 '16 at 6:04
  • That is obvious. Update your fail function to get the error details. something like this function fail(sender, args) { alert("Failed. Message:" + args.get_message()); } – Nadeem Yousuf Aug 22 '16 at 6:09
  • 'Start Time' does not exist it may have been deleted by another user this is the error, Start Time is column name – Madhav Aug 22 '16 at 6:17
  • As mentioned in my first comment, you need to use internal names of the fields not the display name. – Nadeem Yousuf Aug 22 '16 at 6:21
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.

  • 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 4:22
  • @Ma6139735, you should ask a new question for this. Include your code in the question. – Nadeem Yousuf Aug 26 '16 at 5:20
  • yes i did that,sharepoint.stackexchange.com/questions/191877/… – Madhav Aug 26 '16 at 5:23

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.