Force trigger after update with mass update
I have a table called "Bancos" where I import a CSV file with the bank statement.
As I wasn't sure on how to, once imported all records, create a new entry on a different table "Entradas/Salidas" (somehow trigger on create didn't work with imported files), I've created a button "Exportar Asiento" that once set to "true" triggers that action.
The trigger code, looks something like this:
if 'Exportar Asiento' = true then
let rbanco := this;
let repes := cnt((select 'Entradas/Salidas')[Movimiento = rbanco.Concepto and number(Importe) = number(rbanco.Importe) and
'Fecha Asiento' = rbanco.'F. Operativa']);
if repes = 0 then
let nregistro := (create 'Entradas/Salidas');
nregistro.('Fecha Asiento' := rbanco.'F. Operativa');
nregistro.(Movimiento := rbanco.Concepto);
nregistro.(Importe := rbanco.Importe);
nregistro.(Cuenta := first((select Cuentas)['ID Cuenta' = "A100-2"]))
else
null
end
end
The trigger works as expected when updated a record.
As there are many records, I thought that mass update would do the trick. But it didn't.
Thanks for any thoughts on this!
8 replies
-
Just to be clear, you want the button to take all newly imported records from Bancos and create a new record in Entrada/Salidas.
Are you familiar with the for loop command?
-
Marisol Echaide said:
Exactly, that's what I'm trying to recreate with a yes/no switch. Since the action of setting from blank to yes is an update to the record, it serves to activate the trigger. But it's not activated in mass update.Looks like you are correct. Bulk Edit does not trigger the Trigger after update of a field.
Marisol Echaide said:
I'm still not familiar to the for loop command.It is a very powerful command that allows you to modify a set of records. There are some good videos out there on it. But here are the basics:
In our instance, in a button you would start with something like:
for loop1 in select Bancos do end
Line 1, starts our for loop by creating a variable, loop1, but can be called anything you want. Then we tell it what array to use. Here we use the select command to get all the records in the table Bancos. We end with a "do".
Line 2 is where all the hard work goes.
Line 3, is the end command for the loop.
Now we can take your previous code and put inside the for loop and then change any references to "this" to loop1.
for loop1 in select Bancos do if 'Exportar Asiento' = true then let rbanco := loop1; let repes := cnt((select 'Entradas/Salidas') where Movimiento = rbanco.Concepto and number(Importe) = number(rbanco.Importe) and 'Fecha Asiento' = rbanco.'F. Operativa'); if repes = 0 then let nregistro := (create 'Entradas/Salidas'); nregistro.('Fecha Asiento' := rbanco.'F. Operativa'; Movimiento := rbanco.Concepto; Importe := rbanco.Importe; Cuenta := first((select Cuentas)['ID Cuenta' = "A100-2"])) else null end end end
I don't know how many records Bancos has but we can make the code run faster by removing the first if statement. Something like:
for loop1 in select Bancos where 'Exportar Asiento' do let rbanco := loop1; let repes := cnt((select 'Entradas/Salidas') where Movimiento = rbanco.Concepto and number(Importe) = number(rbanco.Importe) and 'Fecha Asiento' = rbanco.'F. Operativa'); if repes = 0 then let nregistro := (create 'Entradas/Salidas'); nregistro.('Fecha Asiento' := rbanco.'F. Operativa'; Movimiento := rbanco.Concepto; Importe := rbanco.Importe; Cuenta := first((select Cuentas)['ID Cuenta' = "A100-2"])) end end
In line 10, it looks like you are linking all new records to the same record in the Cuentas table. You can replace the first(select()) command with just the record Id of the record so you can skip having Ninox do the select over and over again to get the same record Id. Or if you really want to have the first(select()) then you can put it just above the for loop in a variable then use that variable.
-
Marisol Echaide said:
I tried to replace the first(select()) command with just the record ID and though I didn't get any error on the code, that specific field was not selected.That is interesting. I just tried it myself and it worked for me. How did you code the record Id? Did you put “ “ around the number or leave the number by itself?
-
Marisol Echaide said:
Cuenta = "A100-2"So "A100-2" is not the record Id.
Go to the Cuentas table. Add the Id field to the table view. Find the first instance of a record that has A100-2 in the ID Cunata field. Make a note of that record Id and use that.
Content aside
- Status Answered
- 1 yr agoLast active
- 8Replies
- 202Views
-
2
Following