9 Replies Latest reply on Jun 18, 2014 8:51 AM by philmodjunk

    Script Trigger for Printing Multiple Records on Different Layouts

    BryanN

      Title

      Script Trigger for Printing Multiple Records on Different Layouts

      Post

           I have 5 records, each of these utilizes a different layout for data entry as well as printing.  A field "reporttype" in each record says what type of layout it will have (example: Transformer Test).  I have script triggers in the data entry layouts that say when that "report type" field is modified, it will change the layout via calculation to the value in the field (i.e. if I change from Battery Test to Transformer Test, the layout will switch from Batttry Test data entry to Transformer Test data entry.

            

           What I am now trying to do is replicate this functionality for printing.  That way, if I have a found set that contains 5 reports, I can either choose to print 1 report at a time, or, all 5 reports - each with their appropriate print layout.  All while in preview mode (our print script opens a separate window and puts the user right into preview mode).

            

           Any ideas?

        • 1. Re: Script Trigger for Printing Multiple Records on Different Layouts
          philmodjunk

               #after performing your find to get your found set....
               Go To Record/Request/Page [First]
               Loop
                 Go to Layout [//same calculation in your triggered script here]
                 Print
                 Go to Record/Request/Page [Next ; exit after last ]
               End Loop

               This assumes that all your layouts specify the same Tutorial: What are Table Occurrences? name in Layout Setup | Show Records From

          • 2. Re: Script Trigger for Printing Multiple Records on Different Layouts
            BryanN

                 Phil,

                 Is there a way for this to be run while sitting in preview mode? If I'm understanding correctly, the script provided would print the found set 'automatically' for the user then exit back to the data entry interface.

                 Typically, our users will hit the 'print' button, the record will show up in a new window in it's 'print' layout and will go right to preview mode. Many times, users will save as a PDF versus physically print, or sometimes both (Excel I have grayed out via the custom menu set).

                  

                 Basically, what I'm hoping to find is that if they have this window up, they can scroll thru the found set records via the arrows and the layouts will change accordingly both when scrolling and printing.  Does that make any sense?

            • 3. Re: Script Trigger for Printing Multiple Records on Different Layouts
              philmodjunk

                   I would have set it to print the current record, not the found set.

                   But you can replace print with:

                   Enter Preview Mode [Pause]

                   The user can click Continue in the Status ToolBar or press Enter (on the number keypad) to continue past the pause. And they can use Print and/or Save As PDF to print or PDF the current record.

                   Though I might reduce the chance of user error by setting up a modified version of this that isolates the current record as the only record in the found set. That way, the user can't accidentally use "Records being Browsed" to print or PDF a found set that includes records that should be printed from a different layout.

              • 4. Re: Script Trigger for Printing Multiple Records on Different Layouts
                BryanN

                     Got ya.  Is there a way where the user could hit the Save as PDF button to be able to print the found set to one pdf file, all with the correct print layouts?

                • 5. Re: Script Trigger for Printing Multiple Records on Different Layouts
                  philmodjunk

                       #after performing your find to get your found set....
                       Go To Record/Request/Page [First]
                       Set Variable [$Path ; Filepath and field name of PDF file goes here ]
                       Go to Layout [//same calculation in your triggered script here]
                       Save As PDF [ Current Record ; $Path ]
                       Loop
                         Go to Record/Request/Page [Next ; exit after last ]
                         Go to Layout [//same calculation in your triggered script here]
                         Save As PDF [ Current Record ; $Path ; Append ]
                       End Loop

                       If you haven't used a $Path variable before see these links:

                       Saving As PDF in a script: Found Sets to PDF with unique file names

                       More on $Path variables and the script steps that can use them: Exploring the use of a $Path Variable in Scripts

                  • 6. Re: Script Trigger for Printing Multiple Records on Different Layouts
                    BryanN

                         Ahh, it's not working exactly the way I want and I can tell you why:

                         The majority of the records we are using this with, use the same associated table for their layouts.

                          

                         However, there will be records that have to have a layout based on a child table due to the type of data to be entered (via a portal).

                          

                         Any way around that?  I have to do it that way as the layouts based on child tables are List View only layouts versus the  rest that are Form View only.

                    • 7. Re: Script Trigger for Printing Multiple Records on Different Layouts
                      philmodjunk

                           You'll need to add code (an If block)  that checks for these records and uses Go to Related Records to pull up the child records on the report layout based on those child records. The script will then, while still inside the loop, return to the previous layout before looping to the next record in your found set.

                      • 8. Re: Script Trigger for Printing Multiple Records on Different Layouts
                        BryanN

                             Ugh, I'm still having trouble getting this to work right.  I'm not liking the script controls being user facing.  You mentioned above script steps to isolate the current record being browsed in the found set so there aren't any other ones available to print, how would you do that?

                        • 9. Re: Script Trigger for Printing Multiple Records on Different Layouts
                          philmodjunk

                               The trick in isolating the current record is to do it without messing up your original found set of records. One method is to open a new window, isolate the record, print or save as PDF, then close the window. Another is to set up an extra table occurrence of your table and base your original layout on this new table occurrence when performing your find to pull up the records for your reports. Then you can script with either Go to related record or a scripted find to find the lone record on each dedicated report layout without changing the found set in the first layout.

                               A script example based on the second option:

                               Loop
                                  Set Variable [$ID ; SearchLayoutTableOccurrence::PrimaryKey ]
                                  Go to Layout [//select appropriate layout]
                                  Enter Find mode []
                                  Set Field [ReportLayoutTableOccurrence::PrimaryKey ; $ID ]
                                  Perform Find []
                                  Print or Save as PDF Here
                                  Go to Layout [ "SearchLayout" ]
                                  Go to Record/Request/Page [next ; exit after last ]
                               End Loop