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?

9
  • What error are you getting? Also make sure to use internal field names. Commented Aug 22, 2016 at 6:01
  • it is eexecuting fail() function Commented Aug 22, 2016 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()); } Commented Aug 22, 2016 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 Commented Aug 22, 2016 at 6:17
  • As mentioned in my first comment, you need to use internal names of the fields not the display name. Commented Aug 22, 2016 at 6:21

1 Answer 1

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.

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

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.