1 2 3 Previous Next 30 Replies Latest reply on Jul 28, 2011 11:03 AM by EmmettOliver

    Printing a layout based on field contents with a script

    EmmettOliver

      Title

      Printing a layout based on field contents with a script

      Post

      Hi,

      I have forms that need to be printed for separate fields of the same data entry screen.  I would like to print each of the layouts without going to each layout individually.  Ideally, I would like to put a button on the data entry screen that would only print the layouts that are required based on the contents of a field.  For example, if there is one child's name input into the data entry screen, then I need only that one child's form/layout printed.  If there are three childrens' names input into data entry screen, then I need a form for each of the children printed, but I would like that one button on the data entry screen to perform a script that would print the three individual child's form/layout. 

      In each record that is input, the number of children and forms will change based on data entry, so the script would have to read the number of children that have been input.  I have created the layouts and I have created a "number of children field", but I am confused on how to get the script to read the "number of children field" then print each of the corresponding layouts.

      I hope all that rambling makes sense. 

      Thanks!

        • 1. Re: Printing a layout based on field contents with a script
          philmodjunk

          Set variable [$Children ; Value: yourTable::Number of Children]
          go to layout ["layout you need to print"]
          Loop
             Exit Loop if [$Children < 1 ]
             Print [Restore ; no dialog]
             Set Variable [$Children ; Value: $Children - 1 ]
          End Loop

          There are other possiblities.

          If you enter the names of the children in your original layout, for example, the system could print this form for each child with their name already added to the form.

          • 2. Re: Printing a layout based on field contents with a script
            EmmettOliver

            Oh, so I could have only created one layout and have the different child's info brought over?  Would that be cleaner/easier?  I have the children's information on cascading tabs in the data entry form and fifteen different fields associated with each child (ie, DOB's and SSN's).  There can be up to ten children in each record.  So, that would nice to have only one form to create.  I open to other ideas!!

            • 3. Re: Printing a layout based on field contents with a script
              philmodjunk

              What you should do is create separate records for each child and enter each child's data from the start. Each of these records would be related by a common value (same parent perhaps?) to the record your current layout is based on and a portal can list the records for the children.

              In this case, printing the records for the children become a case of performing a find or using Go To Related records to bring them up as a found set on your form's layout and then you'd print, using the records being browsed option to print one copy of the form for each child. This uses an even simpler script than the one I posted earlier as a single print job can now print all the forms.

              • 4. Re: Printing a layout based on field contents with a script
                EmmettOliver

                 I've created separate tables for "report" "children", "mother" and "father" all related by a series #.  So, I might be able to do what you've suggested off of one form?  That would be awesome because I already have the forms created, just need to get the individual child's information printed easily, especially in the case of multiple children.  Thanks a million for your help!

                • 5. Re: Printing a layout based on field contents with a script
                  philmodjunk

                  Mother, and Father could be two records in the same table. You might even have an additional table, Family, that links Parents to children under a common value such as a family name or home address. This set up can even handle "modern family" situations where a child might have more than two individuals listed as parents due to divorce, remarriage, etc.

                  Figuring out how to set up the tables and link the records in relationships lays the basic foundation you'll need for getting your layouts to work for you.

                  • 6. Re: Printing a layout based on field contents with a script
                    EmmettOliver

                    Yes!  I am SLOWLY gettting there.  So, how do I write the script based off the layout using a single button on a different layout.  The data entry layout is where I would like to place the button for printing the form/layout using the different child's information based on the related fields in the "children" table. 

                    • 7. Re: Printing a layout based on field contents with a script
                      philmodjunk

                      Don't know exactly what relationships you have set up here. That's key to knowing exactly how to write the script for this.

                      Say you have a portal to a table called "children" on your current layout...

                      If [ Not IsEmpty ( Children::FamilyID ) //make sure that at least one record in Children exists here]
                          Go To Related Record [Show only related records; From table: Children; Using layout: "FormsLayout" (Children)]
                          Print [Restore ; no dialog]  // Specify the records being browsed option here
                          Go to Layout [original layout]
                      End If

                      • 8. Re: Printing a layout based on field contents with a script
                        EmmettOliver

                        Hey Phil,

                        Thanks for getting back to me.  I was out for some training, but today I am trying to get the script written, but when I get to the Using layout, I cannot get the specify layout pop up window to populate with any choices.  Any ideas?

                        Thanks!

                        • 9. Re: Printing a layout based on field contents with a script
                          philmodjunk

                          The layout must be a layout that refers to the same table as your portal. Make sure that your form layout is based on Children, just like the portal.

                          • 10. Re: Printing a layout based on field contents with a script
                            EmmettOliver

                            Nice.  Well, it's working (woohoo!) but it only prints the first of four records that are populated.  How will I get it to recognize if there are say only two childen records or six or nine, and print the correct number all at once.  When I choose records being browsed it prints a blank for four times and when I choose current record, it prints the same form - the first record - four times.  Would I need to insert some sort of calculation in the script to get it to count the number of say, Child # 1 First Name, Child # 2 First Name, etc, then print those fields for each child?  (I have children as a table for all of the children in the family with one related mother).  I guess the original suggestion of having each child as a separate record is required?  If yes, I guess I could use the first route above and use the following script with forms for each child?

                            Set variable [$Children ; Value: DSU Report::# of Children]
                            Go to layout ["CCJ Form" (DSU Report)]
                            Loop
                               Exit Loop if [$Children < 1 ]
                               Print [Restore: \\12AUST2872FS03\2871_XR7345_1121 ]
                               Set Variable [$Children ; Value: $Children - 1 ]
                            End Loop

                            Now, I tried the above too, but again it only printed the first layout.  Is there a way for FM to count the "# of Children"  then print the four different layouts?  That seems like of lot of steps, huh?Thanks!

                            • 11. Re: Printing a layout based on field contents with a script
                              philmodjunk

                              I'd base CCJ Form on your children table, not the DSU Report table if this Form is to be printed once for each child. THen Go To Related Records should work and you need only one Print to print all the forms for all the children.

                              Your script looks correct. If you have FileMaker Advanced, you might use the dataviewer and script debugger to step through this script and watch the value in $children and watch the script execute to see if you spot any problems.

                              If you do not have advanced (you should get a copy), Add a show custom value step as the first line inside the loop and use it to display the value of $children to see if it is getting the correct value here.

                              • 12. Re: Printing a layout based on field contents with a script
                                EmmettOliver

                                Hi Phil,

                                Well, I took the idea of creating a Family table and using the _kf_FamilyID in the Child, Mother, Father and InterestedParty tables to get them related, but I am still having trouble getting the CCJ and PR forms for each child to print.  I've taken screen shots of the relationship tables and the three layouts (Report - for data entry, CCJ and PR for printing).   Here's the link to the shared files. 

                                http://www.4shared.com/photo/gXnG5Sie/FM_CCJ_Layout.html
                                http://www.4shared.com/photo/xxLGX2iI/FM_PR_Layout.html
                                http://www.4shared.com/photo/u6kYkmD4/FM_Relationship.html
                                http://www.4shared.com/photo/mGdtsEvA/FM_Report_Layout.html

                                The idea is to click on the printer icon and be able to print one CCJ form and two PR forms for each child.  On the form will also be the mother(s) and father (s) for each child.  Whereas before, I could get the first child to print, now I cannot get any of them to print.  Maybe I messed up on the relationships?? Please help.

                                Thanks, Emmett

                                • 13. Re: Printing a layout based on field contents with a script
                                  EmmettOliver

                                  Oops, here's the script I'm using:

                                  If [not is empty (Child::_kf_FamilyID)]

                                     Go to Related Record [Show only related records; Match found set; From table; "Child"; Using layout "CCJ Form" (report_Child)]

                                     Print [Restore: XR7345; No dialog]

                                     Go to Related Record [Show only related records; Match found set; From table; "Child"; Using layout "PR Form" (report_Child)]

                                     Print [Restore: XR7345; No dialog]

                                     Go to Layout [orginal layout]

                                  End if

                                  • 14. Re: Printing a layout based on field contents with a script
                                    philmodjunk

                                    I don't see any reaon for "Match found set here" and you don't need to use Go To Related records twice. The first Go To Related Records will create a found set for just the related records for both layouts as they are both based on the same table occurrence (report_child).

                                    1 2 3 Previous Next