10 Replies Latest reply on Dec 1, 2009 4:47 PM by philmodjunk

    Printing Script Doesn't Work With More Than 1 Record

    senriz_1

      Title

      Printing Script Doesn't Work With More Than 1 Record

      Post

      Hello... I'm a novice using FMP9 Adv.  I have a printing script that is pretty complex and works beautifully when there is only ONE record.  A little background so the script is understood... I have a layout that has 49 tabs and each tab is represent of a form.  The user selects which form to print in a set by a checkbox.  When these forms get printed they MUST be numbered Pg __ of __.  My print checkbox is called Print1, Print2, etc.  When there is more than one record created whether pertaining to the same student or another I get funky page numbering, like Pg 14 of 7.   And sometimes I get pages from another record that have been previously saved, while other times a particular selected form doesn't even print in the set.  When I remove all but one record... it works perfectly.  Below is my script, scaled down due to the multitude of forms.  Any help would be greatly appreciated.  Also, please note the second Print to PDF is an "append".  Thanks!!

       

      Set Field [ Global::gTotalPages; IEP:: Print1 + IEP:: Print2 + IEP:: Print3 ]
      Set Variable [ $fileName; Value:"file:" & Get(DesktopPath) & "GenerateForms" & ".pdf" ]
      Set Field [ Global::gPageNumber; 0 ]
      Go to Layout [ “IEP Forms” (IEP) ]
      If [ ValueCount(IEP:: Print1) > 0 ]
      Go to Layout [ “Form 1” (IEP) ]
      Print Setup [ Orientation: Portrait; Paper size: 8.5" x 11" ]
      [ Restore; No dialog ]
      Enter Preview Mode
      Go to Record/Request/Page  Last ]
      Set Field [ Global::gPageNumber; Global::gPageNumber + Get ( PageNumber ) ]
      If [ Global::gPageNumber = 1 ]
      Save Records as PDF [ File Name: “$fileName”; Current record ]
      [ Restore; No dialog ]
      End If
      End If
      Go to Layout [ “IEP Forms” (IEP) ]
      If [ ValueCount(IEP:: Print2) > 0 ]
      Go to Layout [ “Form 2” (IEP) ]
      Print Setup [ Orientation: Landscape; Paper size: 11" x 8.5" ]
      [ Restore; No dialog ]
      Enter Preview Mode
      Go to Record/Request/Page  Last ]
      Set Field [ Global::gPageNumber; Global::gPageNumber + Get ( PageNumber ) ]
      If [ Global::gPageNumber = 1 ]
      Save Records as PDF [ File Name: “$fileName”; Current record ]
      [ Restore; No dialog ]
      Else
      Save Records as PDF [ File Name: “$fileName”; Current record ]
      [ Restore; Append; No dialog ]
      End If
      End If
      Go to Layout [ “IEP Forms” (IEP) ]
      If [ ValueCount(IEP:: Print3) > 0 ]
      Go to Layout [ “Form 3” (IEP) ]
      Print Setup [ Orientation: Portrait; Paper size: 8.5" x 11" ]
      [ Restore; No dialog ]
      Enter Preview Mode
      Go to Record/Request/Page
      [ Last ]
      Set Field [ Global::gPageNumber; Global::gPageNumber + Get ( PageNumber ) ]
      If [ Global::gPageNumber = 1 ]
      Save Records as PDF [ File Name: “$fileName”; Current record ]
      [ Restore; No dialog ]
      Else
      Save Records as PDF [ File Name: “$fileName”; Current record ]
      [ Restore; Append; No dialog ]
      End If
      End If

      Enter Browse Mode
      Go to Layout [ “IEP Forms” (IEP) ]

        • 1. Re: Printing Script Doesn't Work With More Than 1 Record
          Sorbsbuster
            

          Confession: I have not read your script in detail - but: I seem to remember reading in the 'Upgrade' notes for a recent upgrade that a bug that it was to fix was '...when printing to PDF where the starting page number was not 1'.

           

          Maybe this applies in your case (or could, even when you get this bug fixed!)

           

          Alan

          • 2. Re: Printing Script Doesn't Work With More Than 1 Record
            philmodjunk
              

            I have more questions than answers:

             

            I spotted some things in your script that don't make sense to me (but might with more explanation from you):

             

            Set Field [ Global::gTotalPages; IEP:: Print1 + IEP:: Print2 + IEP:: Print3 ]

             

            The above line implies that Print1, Print2 and Print3 are number fields containing the number of pages for each separate form.


            But

             

            If [ ValueCount(IEP:: Print1) > 0 ]

            Suggests that Print1 is a field formatted as a value list with multiple values and should be a text field.

             

            Don't see why you've done this and how it could work correctly for you.

             

            (PS. I got rid of the pesky emoticons by inserting a space between the 2nd colon and the "P" in these two lines of your script.)

            • 3. Re: Printing Script Doesn't Work With More Than 1 Record
              senriz_1
                

              I was wondering how those emoiticons kept popping.  Thanks. 

               

              Okay... First, the Print1 is a text field that has a Value List of 1, 0.  I guess I could have easily put Yes or No.  Anyway, ONLY the checkbox next to the 1 is viewable on the layout tabs (each tab represents a form).  This box gets checked if the user wants it included in the set of forms to be printed.  Whether a user chooses Form 3, 17, 32, and 48 is has to be numbered Pg 1 of 4, 2 of 4, 3 of 4, 4 of 4. (hence, each page must be number consecutively with the total pages included.

               

              The Set Field [ Global::gTotalPages, IEP:: Print1 + IEP:: Print2 + IEP:: Print3 ] is supposed to count how many checked checkboxes to create the Total Page count (gTotalPages).   And now, is counting them for all the records, not the current record.

               

              The script line, If [ ValueCount(IEP::Print1) > 0 , is supposed print that particular page starting with Pg 1 of ??, if the checkbox is checked.  NOW, when I created the Print1, Print2, Print3 fields I didn't realized these fields should have been number fields.  I did try changing them back to number fields but it screwed up the script, so I just left it as a text field and that is why I use the ValueCount ... it counts the X in the checkbox as 1 or 1 character.  Everything in this script works perfectly as long as there is only ONE record and no more.  Now it has bizarre page numbering, like 21 of 7.  

               

              I have no problem re-doing or changing things around in the script, so whatever assistance you can give me I'd be truly grateful.

              • 4. Re: Printing Script Doesn't Work With More Than 1 Record
                philmodjunk
                  

                IEP:: Print 1 is a check box formatted field that is either 1 or empty correct? If so changing the field to type number should not affect how your script behaves. If it does you may have more than one value in the field. If you store a value in a field by hand and then format the field with check boxes and none of the check box values match the value you typed in earlier, the field will appear empty when in actuality it is not. If this is possible, you might want to place a copy of your field setup as an edit box several rows of text high and inspect things to see if that is possible.

                 

                In any case, that means that

                 

                If [ ValueCount(IEP:: Print1) > 0]

                 

                Could be rewritten as

                 

                If [ Not Isempty(IEP:: Print1) ]

                 

                or

                 

                If [IEP:: Print1 = "1"]

                 

                and you should get identical results unless the issue I mention at the top is a factor.

                 

                Under no circumstances can IEP:: Print1 + IEP:: Print2 + IEP:: Print3 add up anything but either the current record (if IEP is the name of the current layout's table) or the "First" related record. (If IEP refers to the name of a related table's TableOccurrence).

                 

                It may look like that, but I'd double-check to see what values are really being stored in the check box fields if I were you.

                 

                 

                • 5. Re: Printing Script Doesn't Work With More Than 1 Record
                  philmodjunk
                     PS. given that you are using FMP 9 adv have you tested this script while using the debugger and data-viewer to watch what happens as you step through the script?
                  • 6. Re: Printing Script Doesn't Work With More Than 1 Record
                    senriz_1
                      

                    I did get the Set Field [Global::gTotalPages, IEP:: Print1 + Print2 + Print3] back to working again.  I changed all the Print1, Print2, Print3, etc fields to number.  Made sure there were no data in the fields by expanding the field as you suggested.  My Value List consist of only a 1 now.  Verified the field on the Form1, Form2, Form3 is gTotalPages.  It counts them correctly for which ever record I'm on now.  Thank you. My only understanding of that script line is it counts it if there is something in the field...

                     

                    I also changed the If [ ValueCount(IEP:: Print1) > 0 ] to If [ Not Isempty(IEP:: Print1) ] as you suggested.

                     

                    Once I got the gTotalPages fixed I looked for a current PageNumber pattern to see if it would clue me in on the problem.  I finally figured out that it was counting two pages each time, 2 of 4, would be the first page, 4 of 4 would be the second page, etc. Sometimes, it would start out at 5 of 3, then 7 of 3.  This issue affects the first page, Form 1 if selected, from not being included.

                     

                    Hadn't used the Debugger and Data Viewer before.  Upon using it I saw that the script line Set Field [ Global::gPageNumber; Global::gPageNumber + Get ( PageNumber ) ] is counting two pages for the gPageNumber.  ...this is where I left off and will come back to it a little later today.  So... part of this problem is fixed.  Thank you.

                    • 7. Re: Printing Script Doesn't Work With More Than 1 Record
                      senriz_1
                        

                      I was able to do some script debugging and the following are my observations.     

                       

                      On the first line of script before I step through and after I step through that first line of script, it shows the correct number for gTotalPages, but it always shows 2 for the gPageNumber, no matter how many forms are selected to be printed.  The gPageNumber DOES get reset back to 0 upon stepping through the third line.  <!--  /* Font Definitions */ @font-face      {font-family:&quot;Cambria Math&quot;;      panose-1:2 4 5 3 5 4 6 3 2 4;      mso-font-charset:0;      mso-generic-font-family:roman;      mso-font-pitch:variable;      mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face      {font-family:Calibri;      panose-1:2 15 5 2 2 2 4 3 2 4;      mso-font-charset:0;      mso-generic-font-family:swiss;      mso-font-pitch:variable;      mso-font-signature:-1610611985 1073750139 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal      {mso-style-unhide:no;      mso-style-qformat:yes;      mso-style-parent:&quot;&quot;;      margin:0in;      margin-bottom:.0001pt;      mso-pagination:widow-orphan;      font-size:11.0pt;      font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;      mso-fareast-font-family:Calibri;      mso-fareast-theme-font:minor-latin;      mso-bidi-font-family:&quot;Times New Roman&quot;;      color:black;} span.EmailStyle15      {mso-style-type:personal;      mso-style-noshow:yes;      mso-style-unhide:no;      mso-ansi-font-size:11.0pt;      mso-bidi-font-size:11.0pt;      font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;      mso-ascii-font-family:Calibri;      mso-ascii-theme-font:minor-latin;      mso-fareast-font-family:Calibri;      mso-fareast-theme-font:minor-latin;      mso-hansi-font-family:Calibri;      mso-hansi-theme-font:minor-latin;      mso-bidi-font-family:&quot;Times New Roman&quot;;      mso-bidi-theme-font:minor-bidi;      color:#1F497D;      mso-themecolor:dark2;} .MsoChpDefault      {mso-style-type:export-only;      mso-default-props:yes;      font-size:10.0pt;      mso-ansi-font-size:10.0pt;      mso-bidi-font-size:10.0pt;} @page Section1      {size:8.5in 11.0in;      margin:1.0in 1.0in 1.0in 1.0in;      mso-header-margin:.5in;      mso-footer-margin:.5in;      mso-paper-source:0;} div.Section1      {page:Section1;}   --><!--  [if gte mso 10]&gt; &lt;style&gt; /* Style Definitions */ table.MsoNormalTable      {mso-style-name:&quot;Table Normal&quot;;      mso-tstyle-rowband-size:0;      mso-tstyle-colband-size:0;      mso-style-noshow:yes;      mso-style-priority:99;      mso-style-qformat:yes;      mso-style-parent:&quot;&quot;;      mso-padding-alt:0in 5.4pt 0in 5.4pt;      mso-para-margin:0in;      mso-para-margin-bottom:.0001pt;      mso-pagination:widow-orphan;      font-size:11.0pt;      font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;      mso-ascii-font-family:Calibri;      mso-ascii-theme-font:minor-latin;      mso-fareast-font-family:&quot;Times New Roman&quot;;      mso-fareast-theme-font:minor-fareast;      mso-hansi-font-family:Calibri;      mso-hansi-theme-font:minor-latin;      mso-bidi-font-family:&quot;Times New Roman&quot;;      mso-bidi-theme-font:minor-bidi;} &lt;/style&gt; &lt;![endif]  -->And, all my forms display on one page… there is no overflow creating a second page.  So then, I created a third record, and the gPageNumber on the first line of script before and after stepping through showed 3.  After creating a fourth record and running through the steps up through step 10, the gPageNumber became 4, which should be 1 because it's only the First Form (Form1) that is selected to be printed...  ran through the next set of steps for Form2, and the gPageNumber became 8 for the second page, then 12 for the third page.     

                       

                      It appears that the gPageNumber is counting how many records are created among ALL the records.  How do I tell it to only count the particular page for the particular form in the current record only for the gPageNumber?

                      • 8. Re: Printing Script Doesn't Work With More Than 1 Record
                        philmodjunk
                          

                        Isolate just the record you want to print. If you have three records in your found set with a one record/page layout, The script steps:

                         

                        Enter Preview Mode
                        Go to Record/Request/Page  Last ]

                         

                        Move you to the last page of the report which is page 3.

                         

                        Thus
                        Set Field [ Global::gPageNumber;  Global::gPageNumber + Get ( PageNumber ) ]

                         

                        will evaluate as 0 + 3 = 3.

                         

                        How you isolate the current record is up to you. One option is to perform a find in your script such as:

                         

                        Set Variable[$ID; Yourtable::ID field]

                        Enter find mode[]

                        Set Field [YourTable::ID field; $ID]

                        Perform Find []

                         

                        Another option is:

                        Show All Records

                        Omit Record

                        Show Omitted Only

                         

                        Do one or the other at the start of your script.

                        • 9. Re: Printing Script Doesn't Work With More Than 1 Record
                          senriz_1
                             Thank you!!!  I used the Set Variable script steps.  Works perfectly.
                          • 10. Re: Printing Script Doesn't Work With More Than 1 Record
                            philmodjunk
                               For those who might be reading this thread. Preview Mode can't tell whether you might choose to print using "Current Record" or "Records Being Browsed" so it previews all the records in the found set.