9 Replies Latest reply on May 24, 2012 1:11 PM by straka_sh

    Why does "save as PDF" script not work same as "save as PDF" button?

    straka_sh

      Title

      Why does "save as PDF" script not work same as "save as PDF" button?

      Post

       I'm trying to create invoices that are subsummarized by ID_unit.  I go to the layout, sort by ID_unit, get the appropriate layout and information subsummarized, and I want each as PDF to email to each unit.  Here is the problem:

      1.  When I save the PDF using the shortcut button in Preview Mode, the PDF is exactly how I want it to look.

      2.  If I use a simple script to save the PDF of the same layout, with the same sort, in the same folder as #1, it creates the PDF with the header, footer, and body information, but there is no sub summary. 

      I have a script that I'll attach that allows me to create the invoice PDF from anywhere in the database.  And it works well except for this subsummary problem. 

      I then created a simple script of just go to preview mode, save as PDF, go to browse mode, and it still doesn't do the subsummary, even if I'm in the layout I want, with everything sorted to show the subsummaries...

      What's up with this?

       

      PR_Scout_Save_as_PDF_and_Email.JPG

        • 1. Re: Why does "save as PDF" script not work same as "save as PDF" button?
          philmodjunk

          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.

          • 2. Re: Why does "save as PDF" script not work same as "save as PDF" button?
            straka_sh

             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... 

            • 3. Re: Why does "save as PDF" script not work same as "save as PDF" button?
              straka_sh

               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...

              • 4. Re: Why does "save as PDF" script not work same as "save as PDF" button?
                Sorbsbuster

                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.

                 

                • 5. Re: Why does "save as PDF" script not work same as "save as PDF" button?
                  straka_sh

                  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:

                  Individual Sellers

                  Sales Units

                  Commissions

                  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?

                   

                  • 6. Re: Why does "save as PDF" script not work same as "save as PDF" button?
                    philmodjunk

                    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?.

                    • 7. Re: Why does "save as PDF" script not work same as "save as PDF" button?
                      straka_sh

                       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...

                      • 8. Re: Why does "save as PDF" script not work same as "save as PDF" button?
                        philmodjunk

                        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
                        End If
                        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.

                        • 9. Re: Why does "save as PDF" script not work same as "save as PDF" button?
                          straka_sh

                           Phil,

                          Thanks... it works very well now...