2

here am trying to create/save event in custom SharePoint calendar list using JavaScript,here event is getting created at my entered date but issue with time value means it is not saving my entered time value instead of that it saves some time value which has 5/6 hours difference from my entered time value.

My code is as below.

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').format("MM/DD/YYYY HH:mm");
        listItem.set_item('EventDate', dateTime);
        var enddate = $("#txt_endTime").val();
        var enddateTime = moment(enddate, 'DD/MM/YYYY HH:mm').format("MM/DD/YYYY HH:mm");
        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");
}
1

try the following code

        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");
            var startDateTimeNow = new Date(new Date(dateTime).getTime()).toISOString();
            listItem = list.addItem(listCreationInformation);
            listItem.set_item('EventDate', startDateTimeNow);

            var enddate = $("#txt_endTime").val();
            var enddateTime = moment(enddate, 'DD/MM/YYYY HH:mm a').format("MM/DD/YYYY HH:mm");
            var endDateTime = new Date(new Date(enddateTime).getTime()).toISOString();
            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");
        }

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.