5 Replies Latest reply on Apr 24, 2013 7:01 AM by philmodjunk

    OnRecordExit

    Matty_1

      Title

      OnRecordExit

      Post

           Is there a way to have an OnRecordExit type function in filemaker?  I have records with a counter that counts each time an electronic copy of the record has been sent to the accounting department.  I can't use validation because certain fields require that the record be committed before applying the appropriate calculations therefor I keep getting validation messages every time I try to navigate through the fields.  I'd like it to only kick in if I attempt to leave the record without sending an electronic copy off.

            

            

        • 1. Re: OnRecordExit
          philmodjunk

               You'd have to trap each of the events that "Exit" the record:

               Closing the window (OnWindowClose in file options)
               Changing layouts (OnLayoutExit )
               Going to a different record in the same layout (OnRecordLoad)

               To keep from processing the "exit" more than once, you'd need to experiment with setting a value in a global variable when you first put the focus on the record or open it for editing (onObjectEnter on a field) that you then clear the first time you process the "exit".

          • 2. Re: OnRecordExit
            Matty_1

                 so I wouldn't be able to use the field that currently counts up each time I sent an eletronic copy?  Figured: If (ElectronicCounter < 1) would be enough to signal that the accounting departement had note recieved a copy.

                  

                 I'm guessing that by the time OnRecordLoad kicks in it will no longer have access to the original counter?

            • 3. Re: OnRecordExit
              philmodjunk

                   That's why you need to capture the primary key of the current record in a global variable with each OnRecordLoad event. The script has to both check for the ID of a previous record and also save the value of the current record. The other script triggers would simply clear the variable once they have processed the "exit" event.

                   

                        I can't use validation because certain fields require that the record be committed before applying the appropriate calculations therefor I keep getting validation messages every time I try to navigate through the fields.

                   Hmm, what that has to do with this issue is not at all clear to me here, but you might consider experimenting with the onObjectValidate event to capture and process validation issues before the field based data validation can kick in.

              • 4. Re: OnRecordExit
                Matty_1

                     So If I'm to take the global variable route, how would the script look like?  For some reason I'm drawing a compelte blank.

                     I have a primary key field called InventoryADJID and ElectronicCounter which is the field that counts how many times an electronic copy has been sent to the accounting department.

                • 5. Re: OnRecordExit
                  philmodjunk

                       There would be one script for OnRecordLoad and a different script for the other triggers. I'm going to change the original idea by saving the record number rather than the primary key--though the key could be used instead with the right self join relationship

                       If [ Not $$TriggersOff ]
                          If [ $$PreviousRec ]
                              Set Variable [$$TriggersOff ; Value: True ]
                              Set Variable [$Current ; Value: Get ( RecordNumber ) ]
                              Go to Record/Request/Page [$$PreviousRec ; no dialog]

                              #Do whatever you need to do on the exited record here.

                              Go to Record/Request/Page [$Current ; no dialog]
                              Set Variable [$$TriggersOff ; value: False ]
                          End If
                          Set Variable [$$PreviousRec ; value: Get (RecordNumber ) ]
                       End If

                       $$TriggersOff is a variable that I am using to keep this script from tripping its own script trigger in an infinite loop of tripped script triggers. THe script for the other triggers would be nearly the same but the last Set Variable step would set $$PreviousRect to "" to clear the variable.