5 Replies Latest reply on May 20, 2010 8:36 PM by Bonnerbl

    Selecting child record with variable

    Bonnerbl

      Title

      Selecting child record with variable

      Post

      Using Filemaker 10/11. What am I doing wrong here?

       

      I have a table of ITEMS and a related table of PHOTOS of the item. The PHOTO records can be "Printing", "Nonprinting", "Comparable", etc. There may or may not be a related photo for every type.

       

      ITEMS: Item record id, g photo filter

      PHOTO: Photo record id, Related item record id, Photo, Photo Type.

       

      The PHOTO table is a child of ITEMS.

       

      I defined a second relationship between ITEMS and PHOTOS where Item record id = Related item record id AND g photo filter = photo type. So that is table PHOTO2.

       

      Some of the ITEMS have only one child and it is "Nonprinting", or "Comparable".

       

      My layout has several fields from ITEM and one field (the photo itself) from PHOTO2.

       

      In my script I say --

      ...step where I test to see if a report with photos is being requested...

      Set Field By Name [Item::g photo filter;"Printing"]

      Go to Layout ["Items with Photos"(Photo2)

      Show All Records

      Sort Records, Adjust window, Scroll window, etc..

      Go to Record/Request/Page [First}

       

      What is happening is that the report always is displaying a photo whether or not it is a "Printing" photo.

      E.G. - one of the ITEM records has only one associated PHOTO and it is a "nonprinting" type. But that photo is appearing on the layout.

       

      Been struggling with this for several days. Appreciate any feedback or pointers to where I might look.

      Thanks!

       

        • 1. Re: Selecting child record with variable
          comment_1

           


          Hobart wrote:

          What is happening is that the report always is displaying a photo whether or not it is a "Printing" photo.


          What do you want your script to do?

           


          • 2. Re: Selecting child record with variable
            philmodjunk

            I see nothing in your script that selects a specific photo record on your photos layout (it could just as easily by based on Photos as Photos 2 for this purposes--both are different occurrences of the same table.)

             

            Try it this way:

            Set Variable [$ID ; value: Items::Item Record ID]

            Go to Layout [Photos]

            Enter FInd mode []

            Set field [Photos::Related item record id ; $ID]

            Set FIeld [Photos:: Photo type ; Items::g photo filter ]

            Perform FInd[]

            • 3. Re: Selecting child record with variable
              Bonnerbl

              Thanks for you input. I've been trying it out and realize I wasn't specific enough.

               

              My layout contains fields from ITEM and the associated child table PHOTO. The layout is based on ITEM.

              Item::Item record id  --- Item::Item description --- Photo::photo

               

              Every single ITEM record must appear on the layout whether or not it has an associated child PHOTO record.  

              If there is a "printing" PHOTO I want it on the layout. If there isn't a "printing" photo then that space on the layout should be blank.

               

              So I get an error if I try your find because the Photo::photo type field isn't on the layout.

               

              Conceptually what I need to do is

              - once on an ITEM record do a find for a child PHOTO record of the type "printing" and display the ITEM fields and PHOTO.

              - If there aren't any associated child PHOTO records of type "printing" display the ITEM fields and nothing in the PHOTO space.

              - If there aren't any associated child PHOTO records of any type, display the ITEM fields and nothing in the PHOTO space.

              • 4. Re: Selecting child record with variable
                comment_1

                You don't need to find anything in the PHOTO table. If you are on a layout of the ITEM table, any find you perform in the PHOTO table has no significance.

                 

                Looking back at your original post, your script should work fine for your stated purpose - except for two things:

                 

                1.
                Set Field By Name [Item::g photo filter;"Printing"]

                Change that to:

                Set Field [Item::g photo filter;"Printing"]

                 

                 

                2.

                You say that  "The layout is based on ITEM" - but your script says that the layout is based on Photo2.



                • 5. Re: Selecting child record with variable
                  Bonnerbl

                  Hmmmm. Got it working. Does exactly what I wanted - display every item  and include a photo if there is one of the type "printing".

                   

                  I have a second relationship (PHOTO2) between ITEM and PHOTO based on record id and photo type.

                  My layout has fields from ITEM and the image itself PHOTO2:IMAGE.

                   

                  My script says ---

                  Set Field[Item::g Photo Type;"Printing"]

                  Go to Layout [Items with Photo(Item)]

                  Show All Records

                  etc.

                   

                  Am not quite sure why it is now working but it is. I did correct the record the layout was based on,

                  changed Set Field by Name to Set Field, and made sure the image field was PHOTO2:IMAGE.

                   

                  THANK YOU and PHIL very much for the additional information. Though my final solution isn't what he

                  suggested, by puzzling through his suggestion and your specifics I was able to see flaws in the original.