0

Trigger on create with numeric fields

I am creating a table from another table with trigger on create with this code.

let a := Factura.Cliente.Cliente;
let b := Empresa;
let c := Monto
let d := Fecha
let p := (create Flujo);
p.('Cliente / Proveedor' := a);
p.(Empresa := b);
p.(Concepto := "Ingresos");
p.('Monto Prov' := c);
p.(Fecha := d)

It works for all text fields but not for numeric fields like date and amount.

Please help.

17 replies

null
    • Fred
    • 2 mths ago
    • Reported - view

    Just to verify that Monto and 'Monto Prov' are actual number fields and Fecha in both tables are date fields.

      • Mario_Cuzzi
      • 2 mths ago
      • Reported - view

       That's right, Fred.

    • John_Halls
    • 2 mths ago
    • Reported - view

    There are a couple of missing semi-colons in your code

    let c := Monto
    let d := Fecha

     regards John

      • Mario_Cuzzi
      • 2 mths ago
      • Reported - view

       

      Thanks John.
      It doesn't work either
      It works in
      let b := Company;
      I assume it's because it's a text field.

    • Fred
    • 2 mths ago
    • Reported - view

    Can you post a sample DB?

    • Mario_Cuzzi
    • 2 mths ago
    • Reported - view

    This is my original table

    It has the following trigger

    I get the following result

    What am I doing wrong?

      • Fred
      • 2 mths ago
      • Reported - view

       can you post screenshots of the edit fields  window for each table?

    • Mario_Cuzzi
    • 2 mths ago
    • Reported - view

    Sure.

    Thank you very much for your help.

    • szormpas
    • 2 mths ago
    • Reported - view

     Hi,

    I think the issue arises because you have put your code inside the 'Trigger on new record'.

    Ninox runs your code instantly when you create a new record on the Table Facturado before you have the time to enter any values on the new record fields.

    • szormpas
    • 2 mths ago
    • Reported - view

     I suggest to put your code inside the 'Triger after update'.

    • John_Halls
    • 2 mths ago
    • Reported - view

    Hi 

    Can I suggest that original code

    let a := Fecha;
    let b := Cliente;
    let c := 'Linea';
    let d := Monto;
    let p := (create 'Flujo de Caja');
    p.('Fencha Flujo' := a);
    p.('Concepto Flujo' := "Ingresos");
    p.('Cliente Flujo' := b);
    p.('Linea Flujo' := c);
    p.('Monto Flujo' := d)
    

    can move from saving each field as a variable to saving the record as a variable and referencing the fields from this, and also not saving the new record to a variable.

    let a := this;
    (create 'Flujo de Caja').(
       'Fencha Flujo' := a.Fecha;
       'Concepto Flujo' := "Ingresos";
       'Cliente Flujo' := a.Cliente;
       'Linea Flujo' := a.'Linea';
       'Monto Flujo' := a.Monto
    )
    

    This, though, doesn't help with your original query.  If you are putting this in a Trigger after update you might want to check that all the fields are filled in before any new records are created. If not you could end up with a new record for every field that you fill in.

    Regards John

      • szormpas
      • 2 mths ago
      • Reported - view

        Hi,

      we could also use an if statement to check if all the fields are filled in to avoid duplicates:

      let x := this.Text1;
      let y := this.Text2;
      if x and y then
          (create Table2).(
              Text1 := x;
              Text2 := y
          )
      end
      
    • Mario_Cuzzi
    • 2 mths ago
    • Reported - view

    thanks but it doesn't work either

      • John_Halls
      • 2 mths ago
      • Reported - view

       How you proceed depends on your reason for copying the data. Should the record in 'Flujo de Caja' always have the same data as Facturado, any changes in one updates the other. Or do you want the data in 'Flujo de Caja' fixed so that it always shows what was originally posted in Facturado. Or is this acting like an audit trail so that all changes are tracked over time with many records?

      • szormpas
      • 2 mths ago
      • Reported - view

        To add to what John says, is the process really necessary to automate, or could you just copy the text manually? You could use a button to "copy" or "duplicate" the record, for example.

    • Mario_Cuzzi
    • 2 mths ago
    • Reported - view

    Hi,

    The reason I want to do this is that I have several tables with different structures, for example, my billing table has a "customer" field, while my payment table has a "supplier" field. I also have a bank transfer table and others. I want to make a report of all the movements of the month, whether income, expenses or transfers, ordered by the date of the movement.
    That is why I thought of creating a table that indicates all the movements, filter them by month and order them by date.
    If you have a better way to do it please help me.

    Thank you very much for your help.

    • Mario_Cuzzi
    • 2 mths ago
    • Reported - view

    Hi,

    I've already solved it by taking only the reference number and calculating all the remaining fields.

    Thank you very much for your help and advice.

Content aside

  • Status Answered
  • 2 mths agoLast active
  • 17Replies
  • 84Views
  • 4 Following