onBeforeEventChanged event Issue

Hi,

I am having an issue with the onBeforeEventChanged event. When an event is changed via drag and drop I have a validation check run to make sure the user has permission to update an event. When the page is fresh and I move the event to a different area, I will receive an error message that it can’t be moved. But then the event does not go back to its original location. It will move to the correct time but not the correct resource. Any subsequent moves it will return it correctly. I’ve included the code that is executed and a zipped video showing what happens. Any clues as to what might resolve this issue?

    scheduler.attachEvent("onBeforeEventChanged", function (ev, e, is_new, original) {
        var updated = true;
        var permissionName = '';
        switch (ev.type) {
            case "WorkOrder":
                permissionName = "Service Appointments";
                break;
            case "Job":
                permissionName = "Job Appointments";
                break;
            case "Technician":
                permissionName = "Technician Activities"
                break;
            default:
                permissionName = "";
        }
        if (COMMON.getPermission(permissionName, "CanEdit") == false) {
            dhtmlx.alert({
                title: "Error",
                type: "alert-error",
                text: $.i18n('EditPermissionDenied')
            });
            updated = false;
        }

        if (updated && ev.appointmentStatus == "COMPLETE") {
            updated = false;
            dhtmlx.alert({
                title: "Error",
                type: "alert-error",
                text: $.i18n('CompletedAppointmentError')
            });
        }
        if (updated) {
            schedulerLayout.cells('b').progressOn();
            var appt = APPOINTMENTDS.prepareAppointmentForSave(ev);

            var updateResult = APPOINTMENTDS.updateAppointment(appt);

            if (updateResult.result == true) {
                var data = updateResult.data;
                data.start_date = data.start_date.replace('T', ' ').replace('Z', '');
                data.end_date = data.end_date.replace('T', ' ').replace('Z', '');
                data.color = SCHEDULECOLORSFORM.getColorForProperty(data.appointmentStatus);
                scheduledApptsDS.update(ev.id, data);
                scheduler.updateView();
                udpated = true;
            }
            else {
                var data = updateResult.data;
                dhtmlx.alert({
                    title: "Error",
                    type: "alert-error",
                    text: data.error
                });
                updated = false;
            }
            schedulerLayout.cells('b').progressOff();
        }
        return updated;
    });

onBeforeEventChanged.zip (1.69 MB)

Hello,

Perhaps the cause of it is here:
var updateResult = APPOINTMENTDS.updateAppointment(appt);

If (updateResult.result == true), you update event:
scheduledApptsDS.update(ev.id, data);

The event object is already updated and now it’s not possible to go back to it’s original location.
Seems in this case when you need to update event with some values (start_date, end_date, color, etc.), ‘onEventChanged’ event will be more suitable. To render the updated event please use updateEvent method.
docs.dhtmlx.com/scheduler/api__ … event.html

If this doesn’t help you to solve the issue, please provide with access to your application. We need to reproduce the problem to have the opportunity to help you.