*SOLVED* Numbering Line Items in a grid dilemma

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
ACDC
Posts: 1142
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

*SOLVED* Numbering Line Items in a grid dilemma

Post by ACDC »

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

Code: Select all

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//

Code: Select all

If InvoiceItem IS NEW Then
CreateInvoiceItemLineNo
 
The Process 'CreateInvoiceItemLineNo'

Code: Select all

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
Last edited by ACDC on Thu Aug 24, 2023 11:21 pm, edited 1 time in total.
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Re: Numbering Line Items in a grid dilemma

Post by Rennur »

Try using RemovedInvoiceItem prefix in a BO rule to find all instances above the removed LineNo and REDUCE found LineNos by 1:

Code: Select all

If InvoiceItem WAS REMOVED FROM Invoice.InvoiceItem Then 
FIND InvoiceItem WHERE InvoiceItem IN Invoice.InvocieItem AND InvoiceItem.LineNo>RemovedInvoiceItem.LineNo 
REDUCE InvoiceItem.LineNo BY 1
ACDC
Posts: 1142
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: Numbering Line Items in a grid dilemma

Post by ACDC »

Try using RemovedInvoiceItem prefix in a BO rule to find all instances above the removed LineNo and REDUCE found LineNos by 1:
Absolutely Brilliant!! Works like a charm :shock: Thank you, I learned something new today :D

Code: Select all

InvoiceItem.LineNo>RemovedInvoiceItem.LineNo 
the "Removed" key word, I have never seen that before.
Post Reply