4 Replies Latest reply on Jan 15, 2013 6:59 AM by jbante

    Logging script woes.


      I am a new user of Filemaker, now using FMP advanced 12.

      I would like to emphasize BEGINNER.

      I need to create an audit log of access to a layout/table.

      I have enabled a script trigger on accessing the layout (On Layout Enter)

      The script is as follows


      Set variable [$variable1; Value: Get (AccountName)]

      Set variable [$variable2; Value: Get (CurrentTimeStamp)]

      Freeze Window

      New Window [Style: Document]

      Go to layout [“log” (log)]

      New Record/Request

      Set Field [encounterlog::AccountName; $variable1]

      Set Field [encounterlog::TimeStamp; $variable2]

      Commit Records/Requests [Skip data entry validation; No dialog]

      Close Window [Current Window]


      This, of course, creates an infinite loop as each time the window closes it actives the OnLayout script trigger.

      How can I perform this script on accessing the layout without generating the loop.

      Any suggestions would be greatly appreciated.

      A newb.

        • 1. Re: Logging script woes.

          There are a number of ways to do this. The easiest for a new developer to understand might be this.


          At the top of the script add these lines:

          If [ $AlreadyRan = 1]

               Exit Script


               Set Variable [$AlreadyRan; 1 ]

          End If


          What this does is "turn off" the script trigger after the first go. When you close your log window and the on layout enter triggers it runs the script again but since the variable is set it'll exit.


          All that said, you may want to take a good look at your access logging before you get too far down the road.

          • 2. Re: Logging script woes.

            Nick's suggestion should work fine, but you might want to think about another approach. One issue with the new window/close window will be a screen pop or flash that could be annoying. This will happen even if you open the new window in negative space (something like -30,000 top and left).


            An alternative would be to create a relationship to your log table that allows the creation of records. You'd need to create two unstored calcs (Account Name and TimeStamp) in each table. Then create a relationship to your log table, using both of these fields, than allows the creation of records. This way you could simply do a set field (perhaps the layout name?) in the log table to create a log entry. There would be no screen pop, as everything would happen from the same context. As the timestamp field is unstored it would have a different value every time, creating a new record at each set field.


            Bob Gossom

            • 3. Re: Logging script woes.

              Thanks for the ideas.

              I haven't yet had time to try it out but will try to implement what you have suggested.

              Much appreciated.


              • 4. Re: Logging script woes.

                FileMakerStandards.org has a best practice for dealing with this sort of thing. It's vaguely along similar lines to Nick's suggestion, but more systematized. You might edit your script like so:


                If [not TriggersAreActive]

                Exit Script [Result:True]

                End If


                Set Variable [$~; TriggersDisable]

                New Window [...]

                Go to Layout [...]


                Close Window [...]

                Set Variable [$~; TriggersEnable]



                This way, when the script is triggered the second time, it will check global variable flags controlled by the custom functions and decide to not run.