add event

Based on data from an existing event, we want to create a new event. Here’s the code:

[code]scheduler.attachEvent(“onEventChanged”,function(id,data){

	if (data.Dispo == "Reschedule") {
		eventID = scheduler.addEvent({
			start_date: "18-04-2014 09:00",
			end_date:   "18-04-2014 12:00",
			text:   "Rescheduled",
			Rep: data.Rep
		});

		scheduler.showLightbox(eventID);
	}

return true;
})
[/code]

An event is created, but a few problems are occurring:

  • the lightbox doesn’t come up.
  • we get an error: ‘undefined’ is not an object (evaluating ‘this.getEvent(a)[b]=c’)
  • I’d like to only trigger this event when the data.Dispo is changed to “Reschedule”, not when other data points are changed. right now this will run if I move the event, or for any other reason.

We are using a Data Processor, which creates the event in our system, and sends back a changed ID, which I suspect is messing up the lightbox.

Hello,
instead of scheduler.addEvent, try using scheduler.addEventNow. It opens lightbox initially and sends event data to the server side only if lightbox is saved. Also event will be removed without sending anything to the server if user press cancel.[code]scheduler.attachEvent(“onEventChanged”,function(id,data){

  if (data.Dispo == "Reschedule") {
     scheduler.addEventNow({
        start_date: "18-04-2014 09:00",
        end_date:   "18-04-2014 12:00",
        text:   "Rescheduled",
        Rep: data.Rep
     });
  }

return true;
})[/code]

I’ll try that.

How about the second question? I only want to create the new event when the specific data field is changed to reschedule. As it is, this function is triggered by any change , then checks the value. So if the value was already reschedule, and a time is changed, for example, I don’t want the function to run.

In this case you’ll probably need to catch onEventSave event, which happens before onEventChanged (before the changes are actually applied, so you have access to the previous values).

[code]scheduler.attachEvent(“onEventSave”,function(id, data, is_new){
var old_event = scheduler.getEvent(id);

if (data.Dispo == "Reschedule" && old_event.Dispo != "Reschedule") {
...
}
return true;

});[/code]
docs.dhtmlx.com/scheduler/api__s … event.html

Both of these seem to have the same result:

The lightbox for the initial event closes. The data is saved. Then a gray overlay appears over the screen, but not the lightbox for the follow-up event.

Here’s the error thread that Google Chrome reports:
Uncaught TypeError: Cannot set property ‘!nativeeditor_status’ of undefined 249
scheduler.setUserData 122
dataProcessor.afterUpdateCallback 65
dataProcessor.afterUpdate 66
check 9

Can you please tell me what is wrong with my code? I can’t get past this error.

Thanks.