Double check to make sure that the Sort includes the Sub Summary's "When sorted by" field.
Then select "records being browsed" instead of current record for your save as PDF step.
Edit... when I use the save as PDF through the "File" drop down... it does the same thing as my script when I save "current record" only... because I want each invoice to be saved as their own file...
When I save the PDF through the "File" menu drop down... and save all browsed records, each looks correct, however, I can't send out a PDF file to each unit that contains a page with every unit's invoice on it... because that is what it is doing when I save it that way... 1 PDF with everyone's invoice in it...
Phil... how do I get around the problem that I need to be able to create an invoice PDF file for each individual unit and it seems that "records being browsed" is the only way to get the subsummary to be created. But, when it is records being browsed... that creates an invoice PDF file with 100 pages, each one of a different unit... so then everybody would see every other's invoice...
Is there a way to do a looping "Find" in the script so that each unit would be its own "Found set", the PDF saved, email sent, and then the next unit would be a found set, and so on? Because then, the "records being browsed" would be only one unit at a time in that case?
Thanks for all your help...
If you are in the Order Line Items and print the current record only, I'll assume that is only one line item. Presumably when you do it a different way you are finding all the line items with one Invoice number, sorting them, and then printing 'All Records'. Maybe I have not guessed correctly the table of the layout you go to.
Thank you... I realize now why that "current record" is not working.
I guess I just thought that since it did work (shows all records for that unit and subsummary quantities and total $) when I use the short cut button in the menu bar that it would do the same if I save as PDF in a script. But it doesn't..
To do this then, the way the database is currently configured... there are tables for:
Line Item Orders
and the Invoices are: body = each line item order attributed to that unit. Ex) Unit 202 has 4 line item orders for the 15 products, they will all show up... then sub summarized below is the total of each product and the total retail value of all the orders for that same Unit 202 (because it is sub summarized by Unit)
Won't I somehow need to put a Find/Perform Find calculation (per unit) in my script so that it will find all line item orders for 1 unit (ex Group 110), then it can save "all records being browsed" without also including every other unit's, too?
However, won't that calculation or script step(s) have to somehow "loop" through finding the rest of the units to make sure each one has all their info, too?
Anyone with experience with this? and/or another way to do it?
Or do I need to come up with an entirely different invoicing system (just for the PDF portion, because printing them works just fine)? For example... Do I create an invoice in my Unit table and somehow relate get all my order information to show up there and then print invoices by unit record?
I would loop through the Units records on a Units layout and use Go To Related records to bring up the line item recordss for each Unit on your Unit Invoices Print All layout, then save, PDF and email--returning to the units layout before going to next record etc.
Your current script appears to send out an email for each line item instead of an email for each order. I don't think that's what you want here is it?.
You're right... currently it sends one out for each line item... but I'd like it to send out by unit/order... if I use a Go To Related Records function and the relationship between the two tables is by UnitNumber (ex... Crew123) then how would that look in a script form? I'm still fairly a novice at script writing... and I've never used the Go To Related Records function yet.
Would I create a layout in Units that has all the same fields from LineItem Invoice brought over by the UnitNumber relationship?
Thanks for walking me through this a little...
Any layout based on Units should work. What matters is the table occurrence (box in manage | Database | Relationships) selected in layout setup | Show Records From. The layout must specify an Occurrence of Units that is linked to your lineItems table by UnitNumber. Since you probably have a Units layout with a portal to lineitems, use that one unless it has a script trigger that will interfere when your script changes back and forth between the two layouts.
Here's the script for emailing a single invoice (unit) for the current record in your found set of records on a Units layout.
If [ Not IsEmpty ( LineItem_Orders::UnitNumber ) // make sure that line items exist for this order ]
Go To Related Record [Show only related records; From LineItem_Orders; Using layout: "Unit Invoices_Print_All" (LineItem_Orders)]
Sort Records // must sort if you have sub summary parts or they won't be visible
#Put the steps inside your loop here to save as PDF, Send Mail and Insert PDF into container field
Go to Layout [original Layout]
To send out a group of Invoices, put the above steps inside your loop.
Note that you do not have to enter preview mode to save as PDF. If you do enter preview mode, make sure your script returns to browse mode before your script performs any go to record steps or they will go to the previewed page instead of the next record.
Thanks... it works very well now...