Still having problems with DB triggers !!

Good morning from Gran Canaria.

I´m getting crazy with DB triggers. Please could anyone tell me what is wrong with this code:

This is an onRecordInsert event on the table PROVISIONES and I´m trying to save a record in another table HISTORICO_CLIENTES. Running the code in the debugger I see all the lines are executed without problems, in fact I see that the record in HISTORICO_CLIENTES is created but only temporarily, when I check the data only the PROVISONES record is there and with the IDHISTORICO_CLIENTES field filled.

Please, what am I missing?

/**
 * Record pre-insert trigger.
 * Validate the record to be inserted.
 * When false is returned the record will not be inserted in the database.
 * When an exception is thrown the record will also not be inserted in the database but it will be added to databaseManager.getFailedRecords(),
 * the thrown exception can be retrieved via record.exception.getValue().
 *
 * @param {JSRecord<db:/gsdespachos/provisiones>} record record that will be inserted
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"01097AFC-A34E-4A03-BB43-D2BEB5B5CCF6"}
 */
function provisiones_onRecordInsert(record) {
	// Cargamos el numero de documento
	if(!record.documento){
		var cSQL='SELECT MAX(documento) FROM provisiones WHERE provisiones.idinquilino=?';
		var _ds=databaseManager.getDataSetByQuery('gsdespachos',cSQL,[globals.currentInquilinoID],1);
		if(_ds.getMaxRowIndex()==0 || _ds.getValue(1,1)==null){
			record.documento=1
		}else{
			record.documento=_ds.getValue(1,1)+1;
		}
	}
	
	// Verificamos el estado
	record.activa=1;
	
	// Grabamos el movimiento en el histórico
	/** @type {JSFoundset<db:/gsdespachos/historico_clientes>}*/
	var fsHistorico=databaseManager.getFoundSet('gsdespachos','historico_clientes');
	var recHistorico=fsHistorico.getRecord(fsHistorico.newRecord());
	recHistorico.concepto='Su Entrega Provisión ('+globals.PADL(record.documento.toString(),10,'0')+')';
	recHistorico.fecha=record.fecha;
	recHistorico.haber=record.importe;
	recHistorico.idcliente=record.idcliente;
	recHistorico.idcliente_manual=record.idcliente_manual;
	recHistorico.idprovision=record.idprovision;
	databaseManager.saveData(fsHistorico);
	record.idhistorico_clientes=recHistorico.idhistorico_clientes;
	return true;
}

I have tried also trying to save the record with a relation provisiones_to_historico_clientes.newRecord() BLA BLA BLA, but it does not work either.

Thanks

I have discovered something and I guess it is a bug in RC2.

The code that fires the trigger is:

databaseManager.saveData(recProvision);

Where recProvision is the PROVISONES record that I want to save. If I change that code to ```
databaseManager.saveData()


Thanks.

this is not a bug, but just something we don’t support…

calling saveData() in a table event is a no operation, because that is a recursive call that we don;t allow (your are currently in saveData)

and if you call saveData() with just 1 record only that record will be saved. No other records.
And because of the block of the second saveData() that second record isn’t saved

You can open a feature request to see if we can improve that, maybe we can see that a second call to saveData() did have a record parameter and add that param to the to save records…

jcompagner:
this is not a bug, but just something we don’t support…

calling saveData() in a table event is a no operation, because that is a recursive call that we don;t allow (your are currently in saveData)

and if you call saveData() with just 1 record only that record will be saved. No other records.
And because of the block of the second saveData() that second record isn’t saved

You can open a feature request to see if we can improve that, maybe we can see that a second call to saveData() did have a record parameter and add that param to the to save records…

OK Johan I will open a feature request.