5 Replies Latest reply on Mar 26, 2014 1:37 PM by philmodjunk

    Help With "OnLayoutEnter" Triggered Script

    AdamQuintero

      Title

      Help With "OnLayoutEnter" Triggered Script

      Post

           Greetings-

           I am attempting to use a script that's triggered by "OnLayoutEnter" on a layout with a portal whose table is "MedicalRecord". I'm using a Find step to go to the correct "MedicalRecord", and Go To Portal Row(Select,First) to bring the first row into active state. The Find appears to work, but the first portal row just flashes the active state appearance and then inactive. I admit I'm new to Filemaker Pro, and I'm seeking some much needed guidance.

           Here is the "OnLayoutEnter" script I have so far:

           

                 Freeze Window

           

                Set Error Capture[On]

           

                Perform Find[Restore]

           

                If[ Get(LastError) > 0 ]

           

                End IF

           

                Set Error Capture[Off]

           

                Go to Portal Row[Select;First]

           

                Refresh Window[Flush Joined Cache Results]

           Any suggestions are appreciated. Thank you.

        • 1. Re: Help With "OnLayoutEnter" Triggered Script
          philmodjunk

               I'm not sure that Perform find is really doing what you think that it does.

               Perform find will not find records in the portal's table. It will find records in the layout's table. If your find specifies criteria in the portal's fields, you are finding all layout records that have at least one portal record matching that criteria.

               If [ Get ( LastError ) > 0 ]
               End IF

               does nothing in your script as there are no script steps between the If and End If steps.

               And if you have more than one portal on your layout, you need to put the focus on the portal before executing Go to Portal row. That can be done by using the inspector to give the portal an object name and then go to object can precede the go to portal row step in your script.

               But it appears that you only have one portal, so that's not an immediate issue.

               But your refresh window [flush cached join results] step is removing the focus from the portal row. This script step is rarely needed and does not appear to be needed here so I would remove that script step. If you did need it, you could refresh the window and then use go to portal row to put the focus on the desired portal row.

          • 2. Re: Help With "OnLayoutEnter" Triggered Script
            AdamQuintero

                 Thank you,

                 As for the Go to Portal Row, I only want to select and highlight the first record automatically on layout load.

                 I was using Perform Find to go to a specified record in the layout's table, is this the proper way to orient a layout to specific record? I have the primary key stored in a global variable that I was using in the Perform Find. When I stripped it down to:

                 Freeze Window

                 Perform Find[Restore]

                 Go to Portal Row[Select;First]

                 The layout no longer is associated with the "MedicalRecord" table's entry. No data. I must be going about this all wrong. Any thoughts are appreciated. 

            • 3. Re: Help With "OnLayoutEnter" Triggered Script
              philmodjunk

                   I don't know what you mean by:

                   

                        The layout no longer is associated with the "MedicalRecord" table's entry.

                   Does that mean that you made a change in "Show Records From" in Layout Setup?

                   Otherwise, it is still associated with the same table that it always has, but your script may have found zero records and thus you are looking at an empty found set--no data. If you select "Show All Records" from the records menu, you'll see data on this layout once again.

                   The fact that you are getting zero records would seem to indicate that the criteria specified inside the Perform Find script step--which I can't see from what you have posted so far, does not match to any records in your table.

                   You may find setting up find requests with set fields steps makes it easier to keep track of the criteria used in the find. See this thread for examples of that method: Scripted Find Examples

              • 4. Re: Help With "OnLayoutEnter" Triggered Script
                AdamQuintero

                     PhilModJunk-

                     Thank you for the link, that helped. I don't want to assume this, so I'm going to ask if this is a correct statement:

                     If I use Set Field in Find Mode before I Perform Find, it is not changing the contents of that field in any records, because there is no found set yet? 

                     Again, thank you for your explanation. You have been most helpful.

                • 5. Re: Help With "OnLayoutEnter" Triggered Script
                  philmodjunk

                       It's not changing any data in any records because you are in Find mode instead of Browse mode.

                       Take any FileMaker layout and enter Find mode. Notice how all fields appear empty in Find mode except those that have global storage specified. If you try to enter data into these fields, you'll find that you can enter data into the empty fields but that you can't modify the contents of a global field. It works that way because you are entering find criteria when in Find mode and trying to specify find criteria in a global field--which will have the same value for every record in the table, makes no sense and so FileMaker won't let you do that. On the other hand, you can copy data from a global field and paste it into a non global field to use that data as find criteria on the non global field.

                       Those are the key details that explain why the example scripts work the way that they do.