The following scenario goes into my Freeagent accountancy software, looks for the latest draft invoice and adds a new line item (“invoice item”) to the bottom of it.
However, I only want that to happen if the invoice does not already contain an invoice item matching the same title text.
In Freeagent’s data model, an “invoice” object can contain “Invoice Items”. Example: If I were a tradesperson, Invoice INV316 may comprise invoice items “Sink unblocking”, “Painting bathroom”, “Install of new shower head” etc. But I don’t want to add the planned item via Make if it is already present in the invoice.
Here is how an invoice result looks…
“Invoice Items” is an Array of Collections, each of which has a Description.
In my case, I prefix each Description with a date.
I want a check to be carried out for whether the Description of ANY invoice item contains the text of the new item to be added (eg. “Painting bathroom”) (but not the date). But I don’t know how to do that.
I then imagine adding a Filter between “Get Invoice” and “Add Invoice Item”. “Add Invoice Item” should only happen if none of the Invoice Items collections’ Descriptions contains “Painting bathroom”.
How would you do this?
Fairly sure if revolves around Iterator, or Array aggregator or maps.