NumberLine for InvoiceDetails

Hi, i need to put in first Line of InvoiceDetails, Line = 1, but after adding more lines, how can i get the max line and sum 1 ?

You can iterate through collectionDatasource.getItems() and find a max value.

Hi Konstantin, can you Help me to finish the code ?

Integer numerolinea;
        numerolinea = lineasDs.getItems().?¿

The field that have number of first row is linea .

int max = 0;
for (InvoiceDetails details : detailsDs.getItems()) {
      max = Math.max(max, details.getLinea());

Thanks! WOrking Great!

I know this is an old post but, do you have any working examples for the above code? I’ve been trying to implement by placing in an Entities Edit controller, but I am not having any luck. I too need to number related added row details 1,2,3,4, etc. for each related master object. Any help would be appreciated.


Hi Raymond
You may try this when you add a row.

    InvoiceLine line = metadata.create(InvoiceLine.class);
            int max = 0;
            Integer lastNum = InvoiceLinesDs.getItems().stream()

Hi mortoza,
Thanks for the assistance. I was able to get this mostly working. I’m invoking the code with a create button for a invoice line table located at the bottom of my Invoice edit screen. This code is adding a line item to the table, and it’s incrementing the line number just fine on the added rows of the Invoice Line table. My problem is that I need this code to open my Invoice Line Edit window, and set the line number, fill out some additional fields, and then hit OK before it adds it to the Invoice Line table. I appreciate the help.

By adding the following line to the bottom of your code:

openEditor(line, WindowManager.OpenType.THIS_TAB);

I am able to get the editor to open. However, I am recieving the following error trying to close the Invoice Edit screen after the lines are properly added:
Unexpected Error:
SQLIntegrityConstraintViolationException: integrity constraint violation: unique constraint or index violation; SYS_PK_10539 table: INTRANET_INVOICELINE

Any Ideas?