0

Copy a reference field into another reference field

Hello,

I’m completely new to Ninox and I’m trying to create a database for my business. It contains Products, Customers and Invoices tables with a Line items subtable of Invoices. So far so good but as well as having a relationship between Invoices - Products and Invoices - Customers I also need to have a relationship between Line items and Customers because I want to see all individual Products that a Customer bought (please see my Data Model). 

Data model

The problem is that each time I’m creating Line items in an Invoice, I have to select not only the Product but also the same Customer I have already selected for the Invoice, over and over again and that is really frustrating when selecting 50+ products. I think I should be able to copy the Customer name with a script included in trigger after update either table level in Line items table or on the field level when selecting the Product but for the life of me I cannot come up with the script. I have combed through the forum answers but I just can’t find a solution that I could apply to my problem (and even if I did I’m not sure I would be able to modify it to my needs). I would very much appreciate your help! 

Invoice tableLine items

4 replies

null
    • Nick
    • 4 yrs ago
    • Reported - view

    In your 'Line Items' table put this code in the 'Trigger after update' box:

    Customers := Invoices.Customer

    • Nick
    • 4 yrs ago
    • Reported - view

    Sorry...

    Customers := Invoices.Customers

    • Eastone
    • Silvia
    • 4 yrs ago
    • Reported - view

    Oh my god! Is it really so simple? I was trying to put together complex scripts with let variables and select statements :-) I guess KISS is really the golden rule here. Thank you very much for your time and help!

    • Nick
    • 4 yrs ago
    • Reported - view

    👍

Content aside

  • 4 yrs agoLast active
  • 4Replies
  • 1189Views