-2
$scope.submitEvent = function () {
                $scope.calculateEndDate()
                var tags = "";
                var termsArray = new Array();
                var targetAudiencefield = "";
                var clientContext = new SP.ClientContext();
                var oList = clientContext.get_web().get_lists().getByTitle('Event');
                var oListItem
                if (window.location.href.indexOf("NewForm") > 0) {
                    var itemCreateInfo = new SP.ListItemCreationInformation();
                    oListItem = oList.addItem(itemCreateInfo);
                }
                else if (window.location.href.indexOf("EditForm") > 0) {
                    oListItem = oList.getItemById(editEventtId);
                }
                oListItem.set_item('Title', $scope.eventData.title);
                oListItem.set_item('Location', $scope.eventData.location);
                oListItem.set_item('Relevant_x0020_URL', $scope.eventData.link);
                oListItem.set_item('fAllDayEvent', $scope.eventData.cb5);
                oListItem.set_item('Notes', $scope.eventData.Body);
                oListItem.set_item('EventType', 1);


                var eventDate,
                    endDate,
                    selectedItem = $scope.eventData.selectedItem;

                if (selectedItem === 'Never') {
                    //oListItem.set_item('fRecurrence', false);

                    eventDate = getDateWithTime($scope.eventData.startDate, $scope.eventData.startTime);
                    endDate = getDateWithTime($scope.eventData.endDate, $scope.eventData.endTime);
                } else {
                    oListItem.set_item('fRecurrence', true);
                    var recurrenceData = getRecurrenceData(selectedItem);
                    oListItem.set_item('RecurrenceData', recurrenceData);

                    var repatEndate;
                    if (selectedItem === 'Daily') {
                        eventDate = getDateWithTime($scope.daily.startDate, $scope.eventData.startTime);
                        repatEndate = $scope.eventData.data=="End by" ?$scope.daily.windowEnd : $scope.repeatEnd
                        endDate = getDateWithTime(repatEndate, $scope.eventData.endTime);
                    } else if (selectedItem === 'Weekly') {
                        eventDate = getDateWithTime($scope.weekly.startDate, $scope.eventData.startTime);
                        repatEndate = $scope.eventData.data == "End by" ? $scope.weekly.windowEnd : $scope.repeatEnd
                        endDate = getDateWithTime(repatEndate, $scope.eventData.endTime);
                    } else if (selectedItem === 'Monthly') {
                        eventDate = getDateWithTime($scope.monthly.startDate, $scope.eventData.startTime);
                        repatEndate = $scope.eventData.data == "End by" ? $scope.monthly.windowEnd : $scope.repeatEnd
                        endDate = getDateWithTime(repatEndate, $scope.eventData.endTime);
                    } else {
                        eventDate = getDateWithTime($scope.yearly.startDate, $scope.eventData.startTime);
                        repatEndate = $scope.eventData.data == "End by" ? $scope.yearly.windowEnd : $scope.repeatEnd
                        endDate = getDateWithTime(repatEndate, $scope.eventData.endTime);
                    }
                }

                if ($scope.eventData.cb5) {
                    oListItem.set_item('EventDate', getDateWithFixedTime(eventDate, 0, 0, 0, 0));
                    oListItem.set_item('EndDate', getDateWithFixedTime(endDate, 23, 59, 0, 0));
                } else {
                    oListItem.set_item('EventDate', eventDate);
                    if (endDate != "Invalid Date")
                        oListItem.set_item('EndDate', endDate);
                    else
                        oListItem.set_item('EndDate', eventDate);

                    // oListItem.set_item('EndDate', new Date(new Date($scope.eventData.endDate).setTime(new Date($scope.eventData.endTime).getTime())));
                }
                if (selectedItem != 'Never') {
                    var newGuid = guid()
                    oListItem.set_item('UID', newGuid);
                }
                //  oListItem.set_item('EndDate', new Date($scope.eventData.endDate + new Date($scope.eventData.endTime).toTimeString()).toUTCString());
                oListItem.set_item('Cover_x0020_Image', $scope.CurrentPost.RollupImage.URL);
                // oListItem.set_item('Notes', $scope.CurrentPost.Body);
                // oListItem.set_item('LatestNewsDefaultImage', _spPageContextInfo.siteAbsoluteUrl + "/Site Asset/LatestNewsDefaultImg.png");
                //  oListItem.set_item('FeaturedNewsDefaultImage', _spPageContextInfo.siteAbsoluteUrl + "/Site Asset/FeaturedNewsDefaultImg.png");
                for (var i = 0; i < $scope.audiences.length; i++) {
                    if ($scope.audiences[i].selected === true) {
                        targetAudiencefield += $scope.audiences[i].AudienceID + ',';
                    }
                }
                targetAudiencefield += ";;;;";
                angular.forEach($scope.Tags, function (value, key) {
                    if ($scope.Tags[key].ticked === true) {
                        termsArray.push("-1;#" + $scope.Tags[key].name + "|" + $scope.Tags[key].id);
                    }
                });
                tags = termsArray.join(";#");
                var field = oList.get_fields().getByInternalNameOrTitle("Tags");
                var taxField = clientContext.castTo(field, SP.Taxonomy.TaxonomyField);
                var terms = new SP.Taxonomy.TaxonomyFieldValueCollection(clientContext, tags, taxField);
                taxField.setFieldValueByValueCollection(oListItem, terms);
                oListItem.set_item('Target_x0020_Audiences', targetAudiencefield);
               // oListItem.set_item('fRecurrence', false);
                oListItem.update();
                clientContext.load(oListItem);
                clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);

                function onQuerySucceeded() {
                    //SP.UI.ModalDialog.close(options);


                    SP.UI.ModalDialog.commonModalDialogClose()
                    window.location = _spPageContextInfo.webAbsoluteUrl + "/Lists/Event/calendar.aspx"
                    console.log('Item created: ' + oListItem.get_id());
                }

                function onQueryFailed(sender, args) {
                    console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
                }
  • Can you post the JSOM code here ? – Gautam Sheth Jan 11 '17 at 6:39
  • I updated the question @GautamSheth – Suriya Jan 11 '17 at 10:19
0

Try it as below:

var oListItem = oList.addItem(itemCreateInfo);


oListItem.set_item('Title', $scope.eventData.title);
oListItem.set_item('Location', $scope.eventData.location);
oListItem.set_item('Relevant_x0020_URL', $scope.eventData.link);
oListItem.set_item('fAllDayEvent', $scope.eventData.cb5);
oListItem.set_item('Notes', $scope.eventData.Body);
oListItem.set_item('EventType', 1);


var eventDate,
    endDate,
    selectedItem = $scope.eventData.selectedItem;

if (selectedItem === 'Never') {        

    eventDate = getDateWithTime($scope.eventData.startDate, $scope.eventData.startTime);
    endDate = getDateWithTime($scope.eventData.endDate, $scope.eventData.endTime);

    oListItem.set_item('EventDate', eventDate);
    oListItem.set_item('EndDate', endDate);
} 
else {
    oListItem.set_item('fRecurrence', true);
    var recurrenceData = getRecurrenceData(selectedItem);
    oListItem.set_item('RecurrenceData', recurrenceData);

    if (selectedItem === 'Daily') {
        eventDate = getDateWithTime($scope.daily.startDate, $scope.eventData.startTime);
        endDate = getDateWithTime($scope.daily.windowEnd, $scope.eventData.endTime);
    } else if (selectedItem === 'Weekly') {
        eventDate = getDateWithTime($scope.weekly.startDate, $scope.eventData.startTime);
        endDate = getDateWithTime($scope.weekly.windowEnd, $scope.eventData.endTime);
    } else if (selectedItem === 'Monthly') {
        eventDate = getDateWithTime($scope.monthly.startDate, $scope.eventData.startTime);
        endDate = getDateWithTime($scope.monthly.windowEnd, $scope.eventData.endTime);
    } else {
        eventDate = getDateWithTime($scope.yearly.startDate, $scope.eventData.startTime);
        endDate = getDateWithTime($scope.yearly.windowEnd, $scope.eventData.endTime);
    }

    oListItem.set_item('EventDate', eventDate);
    oListItem.set_item('EndDate', endDate);
}

In the code that you have posted, below code is inside the else block. That's why I think its not setting value there is no recurrence.

oListItem.set_item('EventDate', eventDate);
oListItem.set_item('EndDate', endDate);
  • ya but above lines for saving the recurrence events, first IF condition is for saving the non-recurrence events, So I think setting false is a problem? Because in default there has one checkbox for recurrences, but I kept its dropdown. @GautamSheth – Suriya Jan 19 '17 at 4:36
  • Yep have edited the code, by default the Recurrence is set to false so I think you dont need to set its value. Is the event now appearing in calendar view ? – Gautam Sheth Jan 19 '17 at 5:35
  • I tried to like that, Still no luck bro, It's not appearing in calendar view? @GautamSheth – Suriya Jan 19 '17 at 9:24
  • Can you add full code right upto executequery ? – Gautam Sheth Jan 19 '17 at 9:44
  • ya sure, can we discuss in chat?@GautamSheth – Suriya Jan 19 '17 at 11:24
0

finally, I found the solution for the issue, It happens because of Event type

Single event and All-day event: Event type should be 0

Recurrence: Event type should be 1

if(Selected item != Never)
{
oListItem.set_item('EventType', 1);
}
else
{
oListItem.set_item('EventType', 0);
}

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.