What user action will "flag" the invoices? If the user just clicks to select an invoice for inclusion in the email, You can add a check box field to click for that purpose.
Then your script can find all records where the check box field is not empty.
Go to related records with the "match found set" option can pull up a found set of line items records on your invoice print layout for all the selected invoices.
Then it's a matter of setting up the layout design and sorting in order to produce a "multiple invoice" billing statement that you can save as PDF and attach to the email.
An alternative approach is to use the "append" option in the save as PDF step to save PDF's of the invoices one at a time but appending them to each other to produce a single PDF file.
I got all the way up to saving the invoice as pdf...but my sorting is not creating individual invoices so it is saving ALL found items in that one invoice.
Also my Invoice part set is as follows
Since you are performing the find on a layout based on OrderLineItem, you do not need to go to related records step. You already have the records that you need for your PDF.
But you need to change the design of this layout.
Add a "print above" sub summary layout part "when sorted by _kf_order_id".
Put the invoice fields that you have currently put into the header into this sub summary part
Add a "print below" sub summary layout part also sorted by the same field. Add the invoice fields that you now have in the footer into this sub summary layout part.
You'll now get groups of line items for each invoice with sub summary layout parts acting as "sub heads" and "sub footers" for each group of line items from the same invoice.
So just to confirm things, I would have the following invoice parts:
1. Sub-summarty (Leading) will have customer name address, etc...
2. Body (which will have ALL my lineitem fields)
3. Sub-summary (Trailing) will have totals from above lineitems.
Does that sound about right. Thanks. -J
Yes. How you sort your line items records will control whether or not your sub summary parts are visible.