4 Replies Latest reply on Feb 6, 2017 6:53 PM by markmeer

    Numbering Pages on Combined Reports for Print

    markmeer

      I've got a (parent) table, "Employees", with several related tables: "training", "incidents", "shifts"..etc.

       

      What I'd like to be able to do is print a report (PDF), that contains all data from parent table and all related tables for a given employee.

      Because of the difficulty with formatting portals, I've written a script to simply print each table separately (from dedicated list-view layouts), appending to a PDF of the same filename each time.  This results in a single PDF with all the information, and is formatted reasonably well (massive pagebreaks notwithstanding...).

       

      Anyway, this approach is acceptable except that I'd like to number the pages with a footer reading "Page (n)  of (totalPages)".

      I've noticed an idea suggestion logged to this effect (which I've upvoted), but I'm curious if anyone can think of a workaround in the meantime...

       

      I know one possibility is to create a single, massive, report table that combines all associated data from related tables beforehand, but the scripting and layout task this presents is a bit overwhelming.

       

      Can anyone think of a way to calculate and insert page numbers (and total page count) when reports are combined like this?

       

      Thanks in advance!

      M.

        • 1. Re: Numbering Pages on Combined Reports for Print
          philmodjunk

          You should be able to find a number of discussions here on this subject. You can set up a script to preview a report and then go to the last page so that you can set a global field or global variable to Get ( LastPageNumber)

           

          This will allow you to set up Page N of Y total pages for a single report.

           

          When combining reports, you have to keep adding to that global with each new report as well as using an "off set" value in a calculation such as:

           

          Get ( PageNumber ) + $$Offset

          to compute and show the current page number. $$Offset would be set to the total pages of the report(s) that preceded the current report.

          1 of 1 people found this helpful
          • 2. Re: Numbering Pages on Combined Reports for Print
            markmeer

            UPDATE:

             

            I've managed to get the total page count displaying properly by creating a global variable, $$pageCount, and performing a find on each layout, then incrementing the $$pageCount variable.  Each list layout for print then has a merge variable in the footer to display the total page count.  Pseudocode:

             

            1. Go to Layout A and perform find based on foreign key.
            2. Go to Last Record in Found Set, and Set Variable $layoutAPageCount = Get(PageNumber)
            3. Go to Layout B and perform find based on foreign key.
            4. Go to Last Record in Found Set, and Set Variable $layoutBPageCount = Get(PageNumber)
            5. ...etc.
            6. Set Variable $$pageCount = $layoutAPageCount + $layoutBPageCount + $layoutCPageCount +...

             

            But I'm still left with the problem of calculating the current page.  In the footer of each report (prior to executing the "Save Record As PDF"), I need a way to insert a field that is {{PageNumber}} offset by the number of previous pages (i.e. start the page count at a calculated value).  Is there a simple way to do this?

            • 3. Re: Numbering Pages on Combined Reports for Print
              philmodjunk

              Don't use {{PageNumber}}

               

              Use an unstored calculation field of Get ( PageNumber ) + $$Offset

               

              Set $$Offset to the total number of pages that you counted from the previous sections of your report.

              • 4. Re: Numbering Pages on Combined Reports for Print
                markmeer

                Thanks philmodjunk!  You are an invaluable resource for those discovering Filemaker like myself. Much appreciated!

                 

                The key was setting the calculation field ("page_number") storage option to Unstored, NOT Global.

                 

                For those who might find it helpful, below is the script to combine several layouts (in this case "Employees", "Shifts" & "Training") into a single PDF. If each table has an Unstored calculation field, "page_number" = Get(PageNumber) + $$pageOffset, then a header/footer can be added that shows "Page <<page_number>> of <<$$pageCount>>":

                 

                Set Variable [$RecordID; Value:Get(ScriptParameter)]

                 

                Go to Layout [“Employees_ListView” (Employees)]

                Enter Find Mode [  ]

                Set Field [Employees::_pkEmployeeID; $RecordID]

                Set Error Capture [On]

                Perform Find [  ]

                If [Get ( FoundCount ) > 0]

                  Enter Preview Mode

                  Go to Record/Request/Page [Last]

                  Set Variable [$pageCount1; Value:Get(PageNumber)]

                Else

                  Set Variable [$pageCount1; Value:0]

                End If

                 

                Go to Layout [“Employee_Shifts_ListView” (Shifts)]

                Enter Find Mode [  ]

                Set Field [Shifts::_fkEmployeeID; $RecordID]

                Set Error Capture [On]

                Perform Find [  ]

                If [Get ( FoundCount ) > 0]

                  Enter Preview Mode

                  Go to Record/Request/Page [Last]

                  Set Variable [$pageCount2; Value:Get(PageNumber)]

                Else

                  Set Variable [$pageCount2; Value:0]

                End If

                 

                Go to Layout [“Employee_Training_ListView” (Training)]

                Enter Find Mode [  ]

                Set Field [Training::_fkEmployeeID; $RecordID]

                Set Error Capture [On]

                Perform Find [  ]

                If [Get ( FoundCount ) > 0]

                  Enter Preview Mode

                  Go to Record/Request/Page [Last]

                  Set Variable [$pageCount3; Value:Get(PageNumber)]

                Else

                  Set Variable [$pageCount3; Value:0]

                End If

                 

                Set Variable [$$pageCount; Value:$pageCount1 + $pageCount2 + $pageCount3]

                 

                #Repeat going though each related table, but this time print to PDF

                Set Variable [$$pageOffset; Value:0]

                Go to Layout [“Employees_ListView” (Employees)]

                Enter Find Mode [  ]

                Set Field [Employees::_pkEmployeeID; $RecordID]

                Set Error Capture [On]

                Perform Find [  ]

                Save Records as PDF [Restore; With dialog:Off; "RecordData.pdf"; Records being browsed]

                 

                Set Variable [$$pageOffset; Value:$pageCount1]

                Go to Layout [“Employee_Shifts_ListView” (Shifts)]

                Enter Find Mode [  ]

                Set Field [Shifts::_fkEmployeeID; $RecordID]

                Set Error Capture [On]

                Perform Find [  ]

                Save Records as PDF [Restore; Append; With dialog:Off; "RecordData.pdf"; Records being browsed]

                 

                Set Variable [$$pageOffset; Value:$pageCount1 + $pageCount2]

                Go to Layout [“Employee_Training_ListView” (Training)]

                Enter Find Mode [  ]

                Set Field [Training::_fkEmployeeID; $RecordID]

                Set Error Capture [On]

                Perform Find [  ]

                Save Records as PDF [Restore; Append; With dialog:Off; "RecordData.pdf"; Records being browsed]

                 

                #Return to original layout

                Go to Layout [original layout]

                Show All Records