6 Replies Latest reply on Feb 1, 2016 12:56 PM by Fahri Akar

    Script to close all windows

    BigMacAl

      Title

      Script to close all windows

      Post

      I've built a database in which several windows can be opened via a single list (in its own, separate window). The names of the windows opened from the list are determined by a calculation, and are thus all different. As a security feature, I'd like the user to be able to close the list window and all windows that may be open at the time before opening a splash window/layout.

      Does anyone know how I may write a script to achieve this? Help would be much appreciated.

        • 1. Re: Script to close all windows
          philmodjunk

          Since you have a script that opens each new window, include a script step like this:

          Set Field [YourTable::gWindowList ; List ( YourTable::gWindowList ; Get ( WIndowName ) ]

          gWindowList would be a text field with global storage specified.

          or you can use:

          Set Variable [$$WindowList ; List ($$WindowList ; get ( WindowName ) ]

          Either way, you are building a return separated list of those windows opened by your scripts. You'd open the new window and then use one of the above scripts to record the name.

          To close all the windows in this list, you can then loop through the list of values, closing windows by name.

          Loop
             Set Variable [$K ; value: $K + 1]
             Exit Loop If [ $K > valueCount ($$WindowList ) ]
             Close Window [Name: Getvalue ( $$WindowList ; $K ]
          End Loop

          Note: if you have FileMaker advanced, you can use a script like this last loop as part of a "close window" script and use a custom menu for the layout used with the parent window that replaces the Close window action with this script. Then, closing the parent window can automatically close all the "child" windows.

          • 2. Re: Script to close all windows
            BigMacAl

            Thanks PhilModJunk. I'll try your suggestions. I do have FileMaker Advanced but I'm not quite sure I understand how the custom menu item replaces the Close Window step. And in this case is the Loop/End Loop script the only one I'd need?

            • 3. Re: Script to close all windows
              philmodjunk

              You need a script step to log the name of each new window and then the looping script to close all the windows logged in the variable or field.

              Make sure that works first. The custom menu trick is an enhancement that may or may not work for your database design. If you open one new window and then open a set of additional windows from it, you can set up a custom menu for the layout of the first window opened so that closing it closes all the listed windows just be clicking it's close button in the corner, using the keyboard shortcut for closing the window or when selcting "close window" from the file menu. You do this by creating a custom menu group where you change the close window option to perform a script with this same loop and then closes that first new window (Don't include the name of the first new window in the same list if you do this).

              • 4. Re: Script to close all windows
                BigMacAl

                Great! Worked a treat although going the custom menu route proved difficult, so I used your first suggestion:

                Open windows:

                Set Variable [$$WindowList ; List ($$WindowList ; get ( WindowName ) ]

                Close all windows:

                Loop
                   Set Variable [$K ; value: $K + 1]
                   Exit Loop If [ $K > valueCount ($$WindowList ) ]
                   Close Window [Name: Getvalue ( $$WindowList ; $K ]
                End Loop

                Does the trick. Many thanks for this - much appreciated!

                • 5. Re: Script to close all windows
                  Fahri Akar

                  Simple... Works great.

                   

                  Loop

                     Close Window [CurrentWindow]

                     Exit Loop If [Get ( RecordOpenState )  ≠ 0]

                  End Loop

                  • 6. Re: Script to close all windows
                    Fahri Akar

                    Or ask user what to do on open state records;

                     

                    Loop

                         #  0 is unlocked records, closes unlocked windows.

                         If [Get ( RecordOpenState )  =  0]

                              Close Window [CurrentWindow]

                         #  RecordOpenState (Locked = other than 0; state 1 and 2 )

                         Else

                         #  Give user a chance to commit, cancel or revert the record.   

                              Show Custom Dialog ["Open RECORD";"This record has not been committed yet."]  (Buttons: Commit, Cancel, Revert)

                              #  Commit button (Default), commits the record.

                              If [Get ( LastMessageChoice ) = 1]

                                   Commit Records/Requests [No dialog]

                              #  Cancel button, exits the script.

                              Else If [Get ( LastMessageChoice ) = 2]

                                   Exit Script [Result:0]

                              #  Revert Button, reverts the record.

                              Else

                                   Revert Record/Request [No dialog]

                              End If

                         End If

                    End Loop