Auto increment a number

I am using this script in the 'Trigger on Create' of a child table 'Invoice Line Items'.  The field in this table is 'Line Number'.  The Parent table is 'Invoices'.  So for every invoice I create multiple line items.

I want the script to increase by '1' for every line item added.

let t := this;
let maxId := max((select Invoices).'Invoice Line Items'.'Line Number');
t.Invoices.'Invoice Line Items'.('Line Number' := maxId + 1)

This script does increase the last (maximum Line Item number) but it changes all the Line Item records to that number.  So instead of 1,2,3,4 etc I get 4 number 4's and on the next 5 number 5's.

I do not understand why this would be since records 1,2,3, are already created so why would they be changed since the script is in the Trigger on Create field of the table.

Can someone please assist.


Thanks in advance

1reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
    • Nick
    • Nick
    • 2 yrs ago
    • Reported - view

    I am using this formula field in the Invoice Line Items table.


    let myID := number(Id);
    let myInvoice := Invoice;
    if Invoice then
    cnt((select 'Invoice Line Items')[Invoice = myInvoice and number(Id) <= myID])


Like Follow
  • 2 yrs agoLast active
  • 1Replies
  • 834Views