I’ll take a beginner’s conceptual shot at this.
Say you have the unfiltered Invoice ID’s to test in $InvoiceID_Collection and
Invoice has a relation to the Invoice_Items named “Invoice_items_Link”
between [Invoices]ID and [Invoice_Items]InvoiceID then
you can get an Invoice_Item entity selection with:
$entSel_Invoice_Items:=ds.Invoice_Items.query(“Invoice_ID in :1”; $InvoiceID_Collection)
At this point we have all invoice items for all invoices.
$entSel_Small:=$entSel_Invoice_Items.query(“InvoiceID = :1”;$obj.ID)
$MoreThan1_ID.push($obj.ID) //build a collection of qualifying invoice IDs
end for each
Unless ORDA has some equivalent to the distinct values count parameter, I would lean toward…
USE ENTITY SELECTION($entSel_Invoice_Items)
DISTINCT VALUES ([Invoice_items]Parent_ID;$aParentID;$aParentIDCount)
SORT the pair and DELETE FROM $aParentID where $aParentIDCount < 2
QUERY Invoices with array $aParentID
$didItWithOrdaSorta:=Create entity selection([Parent])