Too Large Event ID's when adding new events

I have an issue with adding new events in calendar. I have a custom lightbox and am saving the events in the following way:

function save_form() 
 {	
   var ev = scheduler.getEvent(scheduler.getState().lightbox_id);
	var event_id = -1;
	  			
	// if event already exists, reset event fields
	if (ev)
	{
	  	event_id = ev.id;
	  	ev.text = html("studyunit_code").value;
	  	ev.start_date = setDate("start_date", "starttime");
        ev.end_date = setDate("start_date", "endtime");
					
	  	scheduler.endLightbox(true, html("custom_form"));
	 }
	 // else add new event object
	 else
	 {
	  	event_id = scheduler.addEvent(
	  	{
                start_date: setDate("start_date", "starttime"),
                end_date: setDate("start_date", "endtime"),
                text: html("studyunit_code").value
	  	});
	  }
				
	  $("#event_id").val(event_id);
		  		
	  // submit study unit details apart from event object
	  $("#form1").submit();
}

This all used to work fine both to create new events and both to update existing ones. However now I am getting very large event ID’s such as: 1399165341497. A reason to this may be because I frequently delete events and add new events as a bulk of 80 each time. However in my database I have gone up to event 6000.

Of course id’s as large as this aren’t desirable for parsing into an existing java variable and for saving in database. What should I do about this? Is there a way I can start over from event 1 or something?

Thanks in advance.
Would appreciate your help!

Hi,

very large event ID’s such as: 1399165341497.

This is a autogenerated id, which usually considered as a temporary one.

When event is saved to the database, it can obtain a different id and update it on the client-side. Check ‘sid’ and ‘tid’ parameters of the server response

docs.dhtmlx.com/doku.php?id=dhtm … e#response

Hi,

Thanks for your reply. Can you please clarify your answer? I am using java and have the Event Manager with all events overridden. In the save event method below, the DHXEv object is having this temporary ID so event.getD() is being that long number. What should I do so that I get the sid instead of the temporary?

@Override
   	public DHXStatus saveEvent(DHXEv event, DHXStatus status) {
   		Connection conn = SQLHelper.getConnection();
   		PreparedStatement pstmt = null;
   		ResultSet rs = null;
           		
   		try {
   			
   			if (status == DHXStatus.UPDATE) {
   				pstmt = TimetableEvent.updateEvent(conn, event);
   				
            } else if (status == DHXStatus.INSERT) {
            	
            	String eventId = Integer.toString(event.getId());
            	int examID = TimetableEvent.getStudyUnitID(conn, eventId);
            	pstmt = TimetableEvent.insertEvent(conn, event, examID);
            	
            } else if (status == DHXStatus.DELETE) {
            	pstmt = TimetableEvent.deleteEvent(conn, event);
            }

            if (pstmt != null) {
            	pstmt.executeUpdate();
            	
            	if (pstmt.getResultSet() != null)
            		rs = pstmt.getGeneratedKeys();
                
                if (rs.next()) {
                	event.setId(rs.getInt(1));
                }
            }

      	} catch (SQLException e) {
      		System.out.println("[EventsManager.saveEvent() - " + status.name() + "]: " + e.getMessage());
      		e.printStackTrace();
      	
      	} finally {
      		
      		if (rs != null) SQLHelper.closeResultSet(rs);
      		if (pstmt != null) SQLHelper.closePreparedStatement(pstmt);
      		if (conn != null) SQLHelper.closeConnection(conn);
      	}

        return status;
   	}

OK I figured out what is happening. An automatic event id is generated at first and then when the event is inserted, the automatic ID in the database is returned and is being set to the event.

Now I am trying to get this generated event id from the database. As I read the url, I think it is tid which has this data.

I am trying to get the tid by having this event on the scheduler:

scheduler.attachEvent("onAfterUpdate", function(sid, action, tid, tag) 
{   
	  alert(tid);
	  			
	  $("#event_id").val(tid);
	  submit_lightbox();
	
	  return true;
});

but this event isn’t firing. Is there any other way in which I could get this ID from the client side please?

Hi,
you should just set new id for event object:

 } else if (status == DHXStatus.INSERT) {
               
               String eventId = Integer.toString(event.getId());
               int examID = TimetableEvent.getStudyUnitID(conn, eventId);
               pstmt = TimetableEvent.insertEvent(conn, event, examID);
               event.setId(newIdIsHere);
               
            } else if (status == DHXStatus.DELETE) {

EventsManager will send new id to client side in this case.

Yes thanks I set the new ID returned from the PreparedStatement and used onEventIdChange to get this id from the client side. I replied in case of other people having the same problem. Thanks for your help :slight_smile:

scheduler.attachEvent("onEventIdChange", function(sid, tid) 
{   
   alert(tid);				
	return true;
});