I develop an app for processing incoming invoices. You can tag the invoices with supplier, invoice number, amount etc. Also, you can add (I call it) invoice items to divide the amount into different cost centers and projects.
To see the problem, please see the attached gif.
There I select an invoice, add two (!) invoice items and fill out other required properties. Then I save it (assign to professional approval). Then I select the next invoice, and add three (!) invoice items. After saving and selecting the next invoice, the last invoice item is added initially. This happens only when I had more than 2 invoice items before. Why at all and why only from 2 items on?
In "OnVisible" of the Screen, where I can fill out the form, I have following code:
Clear(InvoiceItems);
// "invoice" is the selected invoice that is passed by the screen transition
Collect(InvoiceItems, Filter('Invoice Items Sharepoint List', Invoice.Value=Text(invoice.ID)));
UpdateContext({ invoiceItemTempId: With({ i: Max(InvoiceItems, ID) }, If(IsBlank(i), 1, i + 1)) });
// if there is no invoice item than create a new one, such that there is at least one by default
If(CountRows(InvoiceItems)=0, Collect(InvoiceItems, Patch(Defaults('Invoice Items Sharepoint List'), { ID: invoiceItemTempId, Invoice: { Id: invoice.ID, Value: Text(invoice.ID) } })));
UpdateContext({ startInvoiceItemTempId: invoiceItemTempId, invoiceItemTempId: invoiceItemTempId + 1 });
The "Items" property of the gallery is set to "InvoiceItems".
Does anyone have an idea why this anomaly happens, and then only with at least 3 invoice items?


Report
All responses (
Answers (