Capture generated event.id

Is there a way to capture an event ID after an event is created/stored in my database?
After an event is created in the calendar, I want to be able to click on the event name to go to a details page I created in php.

For each event I do this now:

scheduler.templates.event_text = function(start, end, event) {
			var result = "<b>Name:</b> " + "<a href='http://www.myurl.com/admin_apptinformation.php?Calendar_Id="+event.id+"'>"+event.name+"</a>" + "<br/><b>Reason:</b> " +scheduler.getLabel("reason", event.reason)+ "<br/><b>Status:</b> " +scheduler.getLabel("appt_status", event.appt_status);
			return result;
}

However once an event is added, the calendar must be reloaded in order for this to work. I was hoping that once an event is added, I could just click on the link generated from the above code, but I would need the newly generated event.id for it to work.

Thanks!

code like next will repaint event after it was saved in db, as result it will be rendered with new id and your logic will work correctly without page reloading

dp.attachEvent("onAfterUpdate", function(sid, action, tid){ scheduler.updateEvent(tid); return true; });

Amazing!!! Can the code be adapted to have the event color updated also? My event color and text color is gather using a JOIN statement in my php query that gathers the calendar event info. The colors do adjust appropriately, but only after page refresh.

on client side

dp.attachEvent("onAfterUpdate", function(sid, action, tid, tag){ scheduler.getEvent(tid).color = tag.getAttribute("color"); //this line added scheduler.updateEvent(tid); return true; });

on server side it depends on your existing code, if you are using connector - it can be done as

function afterProcessing($action){ $action->set_response_attribute("color", $some_value); }; $scheduler->event->attach("afterProcessing", afterProcessing); $scheduler->render_....

On server side, can you explain more as to what I’d need to accomplish this?

  function afterProcessing($action){
     $action->set_response_attribute("color", $color_value);
	};
	$scheduler->event->attach("afterProcessing", afterProcessing);

	$SQL = "SELECT event_id, previsit_categories.color, previsit_categories.textColor FROM events_rec LEFT JOIN previsit_categories ON previsit_categories.ID = events_rec.reason where office_ID IN ($office_id) AND appt_status IN ($appt_progress) AND saw_by IN ($provider) AND events_rec.company_ID = '" . addslashes($_SESSION['Company_ID']) . "'"; 
	
$scheduler->render_sql($SQL,"event_id","previsit_categories.color(color), previsit_categories.textColor(textColor)", "", "");

The above $SQL is the query that would generate the appropriate color for the event added. But I don’t think the above code is correct (?) That is also the query I am using to “view” the data in the calendar. Well, it’s a shortened version of it… I deleted the fields for start and end time, etc.

I would need to integrate that query into your suggestion, is that true?

Here’s my code for viewing and inserting and updating:


  if ($scheduler->is_select_mode()){ // ' code for loading data
$SQL = "SELECT event_id,start_date,end_date,text,rec_type,event_pid,event_length,office_ID,reason,patient_ID,name,howheard_ID,promo_ID,events_rec.company_ID, appt_status,saw_by, previsit_categories.color, previsit_categories.textColor FROM events_rec LEFT JOIN previsit_categories ON previsit_categories.ID = events_rec.reason where office_ID IN ($office_id) AND appt_status IN ($appt_progress) AND saw_by IN ($provider) AND events_rec.company_ID = '" . addslashes($_SESSION['Company_ID']) . "'"; 
$scheduler->render_sql($SQL,"event_id","start_date,end_date,text,rec_type,event_pid,event_length,office_ID,reason,patient_ID,name,howheard_ID,promo_ID,company_ID,appt_status,saw_by, previsit_categories.color(color), previsit_categories.textColor(textColor)", "", "");
}
else {	 // code for other operations - i.e. update/insert/delete
$scheduler->render_table("events_rec","event_id","start_date,end_date,text,rec_type,event_pid,event_length,office_ID,reason,patient_ID,name,howheard_ID,promo_ID,company_ID,appt_status,saw_by");

}

Server side code need to return the new color value.
By default server returns something like

<action=“update” sid=“1” tid=“1” />

The above code registers function which will run after data saving. This code will set attribute to response, with new color value ( obtaining such value is separate task ) , so response will look as

<action=“update” sid=“1” tid=“1” color=“some_value” />

and client side code will be use color value to update event object.

I see. I would essentially need an attribute for the color value and then update the color when the event is added on the scheduler.

The color values are stored in a separate table from the events. They are assigned to the event based on a field called “Reason for appointment”. The “reason for appointment” table is joined to the events query to get the color values when the events are loaded onto the scheduler. So no color values are stored in the events table.

However, I don’t know how to assign the color value from this “reasons” table to a new attribute when an event is saved.

Reason 1 = blue
Reason 2 = black
Reason 3 = red

I’m still stumped.

Thanks.

Something like next can be used.
Code takes current value of reason as $action->get_value(“reason”) and fetch related color from DB.

function afterProcessing($action){ $res = mysql_query("SELECT color FROM reason2color WHERE reasonID='".$action->get_value("reason")."'"); $some_value = mysql_fetch_result($res); $action->set_response_attribute("color", $some_value); };

P.S. There is more advanced scenario - you can output the full reason 2 color table on the client side as js array, and add logic to onEventCreated|onEventUpdated handlers, so event color will be changed directly on client side without any server processing. It can be used if this table is not big, and client side modifications is more simple for your than connector tweaking.

Why thank you…

So in theory the below should work:

server code:

 if ($scheduler->is_select_mode()){ // ' code for loading data
	
$SQL = "SELECT event_id,start_date,end_date,text,rec_type,event_pid,event_length,office_ID,reason,patient_ID,name,howheard_ID,promo_ID,events_rec.company_ID, appt_status,saw_by, previsit_categories.color, previsit_categories.textColor FROM events_rec LEFT JOIN previsit_categories ON previsit_categories.ID = events_rec.reason where office_ID IN ($office_id) AND appt_status IN ($appt_progress) AND saw_by IN ($provider) AND events_rec.company_ID = '" . addslashes($_SESSION['Company_ID']) . "'"; 
$scheduler->render_sql($SQL,"event_id","start_date,end_date,text,rec_type,event_pid,event_length,office_ID,reason,patient_ID,name,howheard_ID,promo_ID,company_ID,appt_status,saw_by, previsit_categories.color(color), previsit_categories.textColor(textColor)", "", "");
}
else {	 // code for other operations - i.e. update/insert/delete

      function afterProcessing($action){
     $res = mysql_query("SELECT color FROM previsit_categories WHERE previsit_categories.ID='".$action->get_value("reason")."' AND Company_ID= '" . addslashes($_SESSION['Company_ID']) . "'");
	 $row_color= mysql_fetch_assoc($res);
     $some_value = $row_color['color'];     
     $action->set_response_attribute("color", $some_value);
		};
$scheduler->event->attach("afterProcessing", afterProcessing);
$scheduler->render_table("events_rec","event_id","start_date,end_date,text,rec_type,event_pid,event_length,office_ID,reason,patient_ID,name,howheard_ID,promo_ID,company_ID,appt_status,saw_by");


}

And on client side:

	dp.attachEvent("onAfterUpdate", function(sid, action, tid, tag){
    scheduler.getEvent(tid).color = tag.getAttribute("color"); 
    scheduler.updateEvent(tid);
    return true;
	});

That look correct? :slight_smile:

IT WORKED! IT WORKED! IT WORKED!!!

I cannot tell you how happy I am!

Thanks so much!!!

I have referred people to your extensions, and I will continue to do so.