Scheduler not saving updates after create

Hi,

I have a Timeline scheduler set up, its working fine. One problem I have is that when I save an event ( which works fine, all data is saved into the correct table) when I immediately change that event, either by changing the date or text and save it doesn’t save the update I made.

Steps I take:

Save an event (Successfully)
Double click the event and change the text on it.
Refresh page.
The Event I saved is there but the text changes I made didn’t save.

Any help would be great.

Thanks

The issue happens when event gets new id after saving in the db(e.g. autoincremental) while handler doesn’t return new id value to the client, in such case event has incorrect id on the client and can’t be updated.
How do you save events on the server, can you provide the code?

Just so I am clear, before saving the event into my table the event already has an ID ?

Don’t mean to confuse you but I set the ID of the event I am saving to be null. I do this because I have a trigger on my table to insert a special ID I require, anyway… back to the problem.

I use a beforeInsert on the event, to add in extra fields such as a UserName etc.

 //I use this to add extra fields to the table.
$scheduler->event->attach("beforeInsert",beforeInsert);

	function beforeInsert($action){

		$job_id = preg_replace('/[^0-9]/','',$_GET['id']);
		$engineer = '';
		LogMaster::Log( "Standard Job ID / Parent ID = {$job_id}" );
		
		$query = "SELECT * FROM DT_ScheduledWorkUnit WHERE parent_id = '{$job_id}'";
		$result = mysql_query( $query );
		//first workunit - Get Lead engineer template
		if( mysql_num_rows( $result ) == 0 ){
			LogMaster::Log( "Creating Lead engineer work unit" );
			$lead_engineer_qry = "	SELECT *
									FROM DT_ScheduledWorkUnit
									WHERE IsTemplate = 1
									AND `Name` = 'Lead Engineer'
									AND WorkFlowId = 'SCHEDULED_JOB_LEADER_WF' LIMIT 1";
			$result = mysql_query( $lead_engineer_qry );
			$engineer = mysql_fetch_assoc( $result );
			LogMaster::Log( "Lead Engineer ID: {$engineer['id']}" );
			LogMaster::Log( "Lead Engineer WorkFlowId: {$engineer['WorkFlowId']}" );
		}
		//Not the first, use normal engineer template
		else{
			LogMaster::Log( "Creating Normal engineer work unit" );
			$engineer_qry = "		SELECT *
									FROM DT_ScheduledWorkUnit
									WHERE IsTemplate = 1
									AND `Name` = 'Engineer'
									AND WorkFlowId = 'SCHEDULED_JOB_WORKER_WF' LIMIT 1";

			$result = mysql_query( $engineer_qry );
			$engineer = mysql_fetch_assoc( $result );
			LogMaster::Log( "Lead Engineer ID: {$engineer['id']}" );
			LogMaster::Log( "Lead Engineer WorkFlowId: {$engineer['WorkFlowId']}" );

		}

		$val = $action->get_data();
		$UserId = $action->get_value( "UserId" );
		$username = array();
		LogMaster::Log( "User id {$UserId}" );

		if( !empty( $UserId ) ){
			$query = "SELECT UserName FROM users WHERE id = '{$UserId}'";
			$res = mysql_query($query);
			$username = mysql_fetch_assoc( $res );
			LogMaster::Log( "User Name : '{$username['UserName']}'");
		}

		$correlation_id = uniqid();
		$action->add_field( 'correlation_id' , $correlation_id );
		$action->add_field( 'feature_id' , '51' );
		$action->add_field( 'type_id' , '62' );
		$action->add_field( 'UserName' , $username['UserName'] );
		$action->add_field( 'root_id' , $job_id);
		$action->add_field( 'parent_id' , $job_id);
		$action->add_field( 'WorkFlowId' , $engineer['WorkFlowId']);
		$action->add_field( 'session_id' , '1');
		$action->add_field( 'owner_id' , '1');
		$action->add_field( 'ScheduledTypeId' , 'Job');
		$action->add_field( 'IsTemplate' , '0');
		$action->add_field( 'IconId' , '30');
		$action->add_field( 'Status' , 'New');
		//Set ID to null for DF id
		$action->set_value('id',null);

	}

I hope you got all that. Basically do I need to go find the event I just saved and the a custom update?

Or is there a way of doing this ?

Thanks for help :slight_smile:

Yes, scheduler generates temporary id for new events. But it is not used for insert operation(unless you’ve explicitely added it to the data fields of the connector), so you don’t need to set it to null.

Scheduler should do it automatically. I think it’s better to find the source of the original issue

Can you attach the log or give a complete example so we could test it?

Yes, I do add add the field ID in the beforeInsert. Am I right in saying that the ID that is saved into the table is not returned to the event I see on screen?