12 Replies Latest reply on Dec 4, 2011 4:57 PM by RossHurley

    OnRecordLoad Script Trigger Behaviour

    RossHurley

      Hi all,

       

      I'm having curious behaviour with the OnRecordLoad script trigger set on a layout. The script trigger is designed to run a script which opens a new window when the user changes record. With the trigger enabled, when the script reaches the New Window step, it keeps firing until I about the script, ie produces scores of new windows until I can stop it. To investigate this issue I've reduced the process to just two steps:

       

      1. Set the OnRecordLoad script trigger for this layout to run a test single line script

      2. Have the test script simply have a single step: New Window.

       

      When I exit Layout mode, switch records or even quit and reopen the file, the New Window step keeps firing until I abort the script. It happens on both FMPA10 and 11 on OS X 10.6.8.

       

      I am taking it that this is not expected behaviour but aren't ready yet to say it's a b*g. Or is this behaviour explainable, and there's something simple I've missed?

       

      Any advice (or others able to replicate the issue) would be appreciated.

       

      Thanks,

       

      Ross Hurley

      Adelaide, Australia

        • 1. Re: OnRecordLoad Script Trigger Behaviour
          jose@solutionscay.com

          Hello Ross,

           

          When you open a new Window it shows the same layout and the same record you were in when you ran New Window.

           

          Since you are loading the record again, the trigger fires again, and again, and again...

           

          Try using a variable to decide if the script will run or not.

           

          Best,

           

          Jose

          • 2. Re: OnRecordLoad Script Trigger Behaviour
            pthomas

            You could also name the new window when you create it, and then in the script check the name of the current window, if the current window name equals the name you specified then exit the script otherwise continue and create the new window!

            • 3. Re: OnRecordLoad Script Trigger Behaviour
              jose@solutionscay.com

              That's a good idea, Paul.

              • 4. Re: OnRecordLoad Script Trigger Behaviour
                RayCologon

                RossHurley wrote:

                I am taking it that this is not expected behaviour but aren't ready yet to say it's a b*g. Or is this behaviour explainable, and there's something simple I've missed?

                 

                Hi Ross,

                 

                As Jose has pointed out, what you're seeing is very much expected behaviour and in no sense a bug. All new windows must load a record, so the OnRecordLoad trigger will fire.

                 

                What's not entirely clear is why you would want to do this and what its intended purpose is. Even if you step out of the circular logic you're presently wrangling, the user will (presumably) soon have an unmanageable number of windows on their screen.

                 

                On the other hand, assuming you want a new window-spawned every time the user navigates to a new record, Paul's suggestion won't help, because once the user is in the window that has the 'special' name he's suggesting, further OnRecordLoad calls will no produce any additional windows.

                 

                Notwithstanding the above, if you really do want to do this, you can get there by using a global variable as switch, along the lines of:

                 

                If [$$x]

                Set Variable [$$x; Value: ""]

                Else

                Set Variable [$$x; Value: 1]

                New Window[ ]

                End If

                 

                That will toggle the behavior of the script so that the New Window [ ] command will only occur when you want it to, and setting the global variable to a (boolean) true will disable its next call. However, in addition to the above, you will presumably also need to remember to instantiate the $$x variable on any other occasions (eg in other scripts) when you may want your solution to load a record without yet another new window being spawned.

                 

                Regards,

                Ray

                ------------------------------------------------

                R J Cologon, Ph.D.

                FileMaker Certified Developer

                Author, FileMaker Pro 10 Bible

                NightWing Enterprises, Melbourne, Australia

                http://www.nightwingenterprises.com

                ------------------------------------------------

                1 of 1 people found this helpful
                • 5. Re: OnRecordLoad Script Trigger Behaviour
                  jbante

                  As the other commenters have already pointed out, the problem you're running into is that your triggered script is triggering itself, and the solution is to set some sort of global variable flag to prevent the second triggered script from doing anything. Over at FileMakerStandards.org, we have a set of custom functions we use to handle this for us, both for readability, and to hide the issues dealing with scripts and their sub-scripts both suppressing triggers:

                   

                  http://filemakerstandards.org/display/bp/Suppressible+Triggered+Scripts?focusedCommentId=2785340#comment-2785340

                   

                  So you're script might look something like:

                   

                  If [TriggersAreActive          // Custom function checks global variable flag]

                  # Body of script only runs if another script isn't suppressing triggers

                  Set Variable [$ignoreMe; Value:TriggersDisable          // prevent next trigger from firing]

                  New Window []

                  Set Variable [$ignoreMe; Value:TriggersEnable          // allow subsequent triggers to fire]

                  End If

                  • 6. Re: OnRecordLoad Script Trigger Behaviour
                    RayCologon

                    jbante wrote:

                    So you're script might look something like:

                     

                    If [TriggersAreActive          // Custom function checks global variable flag]

                    # Body of script only runs if another script isn't suppressing triggers

                    Set Variable [$ignoreMe; Value:TriggersDisable          // prevent next trigger from firing]

                    New Window []

                    Set Variable [$ignoreMe; Value:TriggersEnable          // allow subsequent triggers to fire]

                    End If

                     

                    Hi Jeremy,

                     

                    I'm afraid that, as written, that isn't going to work in Ross' situation - because the New Window[ ] step will cause a separate instance of the script to fire, and each instance will acquire a fresh namespace for local $variables. It therefore appears that your $ignoreMe variable is redundant, as it would not be 'seen' by the script instance spawned from the New Window[ ] step.

                     

                    I'm guessing you may have intended to use global $$variables for this?

                     

                    Regards,

                    Ray

                    ------------------------------------------------

                    R J Cologon, Ph.D.

                    FileMaker Certified Developer

                    Author, FileMaker Pro 10 Bible

                    NightWing Enterprises, Melbourne, Australia

                    http://www.nightwingenterprises.com

                    ------------------------------------------------

                    • 7. Re: OnRecordLoad Script Trigger Behaviour
                      jbante

                      The $ignoreMe variable is only a placeholder in the Set Variable steps which are being used to call the custom functions, which are encapsulating actions setting and checking two global $$variables. The $ignoreMe variable itself is wholly irrelevant, thus the name.

                      • 8. Re: OnRecordLoad Script Trigger Behaviour
                        RayCologon

                        jbante wrote:

                        The $ignoreMe variable is only a placeholder in the Set Variable steps which are being used to call the custom functions, which are encapsulating actions setting and checking two global $$variables. The $ignoreMe variable itself is wholly irrelevant, thus the name.

                         

                        Hi Jeremy,

                         

                        Thanks for clarifying.

                         

                        I guess I should try harder to ignore things that say "ignore me".

                         

                        Cheers,

                        Ray

                        ------------------------------------------------

                        R J Cologon, Ph.D.

                        FileMaker Certified Developer

                        Author, FileMaker Pro 10 Bible

                        NightWing Enterprises, Melbourne, Australia

                        http://www.nightwingenterprises.com

                        ------------------------------------------------

                        • 9. Re: OnRecordLoad Script Trigger Behaviour
                          RossHurley

                          Thanks to all who replied. And it was something simple I'd missed. Silly me!

                           

                          To answer Ray who wanted to know what I was trying to accomplish, it is a photo indexing solution where the main detail layout opens in the left half of the monitor with all the detail fields and a thumbnail of the photo. What occurs now is that, if the user wants to see an enlarged view of the photo, they click the thumbnail which runs a script which opens a new window filling the other half of the monitor with a big container field in it. To change the record they close the Photo window, change record, then click the thumbnail again. What I wanted to do was eliminate the need to click the thumbnail if they want to leave the enlarged photo window open as they changed records.

                           

                          Now I realise now is that the process wasn't thought out well anyway. What I'll do when the user changes records is test to see if the Photo window is open. If it is, just do a GTRR to change the photo. But I do have to stop the circular action of the new window triggering the script when it's opened the first time. Paul's suggestion of naming the other window (it does get named Photo anyway) I think will work in my situation. Essentially I see the basic process of the triggered script as:

                           

                          Check the name of the current window.

                              If it's the main record window, check to see if the 'Photo' window is open.

                                  If it is, do a GTRR to change the photo in that window. (If it's not open, don't do anything because the user doesn't want the window open.)

                              If the name of the current window is not the main record window (it, the script was triggered from the Photo window when it was first opened), exit script.

                          End if

                           

                          This is off the top of my head without actually doing the scripting, so there might be some adjustments to be made, but I think the basic process is sound.

                           

                          Ross

                          • 10. Re: OnRecordLoad Script Trigger Behaviour
                            RayCologon

                            RossHurley wrote:

                            ...To answer Ray who wanted to know what I was trying to accomplish, it is a photo indexing solution where the main detail layout opens in the left half of the monitor with all the detail fields and a thumbnail of the photo...

                             

                            Hi Ross,

                             

                            Given that you really only want one additional window, the approach of having an OnRecordLoad script open a new window is unnecessary, and even having the script change records in an existing viewer window is a bit more heavy-handed than you need.

                             

                            I suggest that you consider, instead, simply basing the viewer on a global-field-based utility relationship that is updated by an OnRecordLoad triggered script, and which therefore causes the viewer window (whether or not it is displayed) to keep in step with the record the user is viewing in the 'main' window.

                             

                            In case you want to explore that idea, I'm attaching a very simple demo that shows it in operation.

                             

                            Cheers,

                            Ray

                            ------------------------------------------------

                            R J Cologon, Ph.D.

                            FileMaker Certified Developer

                            Author, FileMaker Pro 10 Bible

                            NightWing Enterprises, Melbourne, Australia

                            http://www.nightwingenterprises.com

                            ------------------------------------------------

                            1 of 1 people found this helpful
                            • 11. Re: OnRecordLoad Script Trigger Behaviour
                              pthomas

                              Hi Ross,

                               

                              Could you not just double the size of your layout to take up the whole screen (you could even script this so that only this particular layout goes full screen, and others stay on half of the screen if that is your requirement for some reason), and put the container field in a portal on the right hand side of the screen?

                               

                              Then the users could just scroll through the portal records to see each of the enlarged photo?

                               

                              Either that or you could just put a single related container field on the right side of the layout. Have the relationship to that field based on a new field you create in your main table to store a photo ID, and then just set the value in that field when someone clicks on one of the thumbnails?

                               

                              Just throwing some ideas out there

                               

                              Cheers,

                               

                              Paul.

                              • 12. Re: OnRecordLoad Script Trigger Behaviour
                                RossHurley

                                Ray, your suggestion sounds good. Also, Paul's suggestion of just widening the window (scripted to show its full width or not depending on user action) is also worth considering.

                                 

                                Thanks all again - I'll pursue one of these strategies.

                                 

                                Ross