Is there a chance of someone cracking this puzzle, I am pulling my hair out on this one
I have an Invoice with InvoiceItems(child) and want to number the InvoiceItems in a logical number sequence of 1 to 50
As I CREATE each InvoiceItem, the new InvoiceItem.LineNo must + 1 on the previously added InvoiceItem.LineNo.
I can get this working to a certain extent based on an example I found in this forum put forward by Vlad , however I have some issues handling an event of one of the items being deleted from the Invoice Item list. Then it all falls apart, re-assigning the new LineNo's is where the challenge is
These are my Rules on the InvoiceItem Object
// This sets the initial value of the InvoiceItem.LineNo so the process below behaves correctly
If InvoiceItem IS NEW AND InvoiceItem.Invoice.CountItems>0 Then
InvoiceItem.LineNo=500 // this just has to be a higher number
ELSE
If InvoiceItem IS NEW AND InvoiceItem.Invoice.CountItems=0 Then
InvoiceItem.LineNo=0
//This starts the process of LineNo numbering//
If InvoiceItem IS NEW Then
CreateInvoiceItemLineNo
The Process 'CreateInvoiceItemLineNo'
1. FIND InvoiceItem WHERE InvoiceItem IN Invoice.Items AND InvoiceItem.LineNo<ThisInvoiceItem.LineNo ORDER BY InvoiceItem.LineNo DESC TAKE BEST
2. IF SEARCH_COUNT>0 Then
ThisInvoiceItem.LineNo=ThatInvoiceItem.LineNo+ 1
ELSE
ThisInvoiceItem.LineNo=1
As mentioned this works fine as long as there are no line deletions taking place. If a user decides to delete line no 4 out of 10 items each item has to be numbered again.
Any clues on how to handle re-numbering on a deletion event
or maybe something more simpler than my version along the lines of indexing the ID attribute to represent simple numbering