Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Trigger on Window Close

Featured Replies

I have a file which has a two windows: a "Main" window that the user uses, and a "Log" window which holds debugging info that they don't generally see. Currently, if the user closes the Main window, then the Log window pops forward, which is not very user-friendly. I'd much rather just close the entire file if the user closes the Main window.

So I'd like something like this:

On Window Close

if ValueCount(WindowNames(Get(FileName))) = 1 and WindowNames="Log" then

# only 1 window left and it's the Log window so close the file

Close File

end if

I thought about doing this in the OnLayoutExit trigger, but the main window has literally 100s of layouts, so adding that to every layout would take forever.

Is there an easy way to do this? In particular, it needs to work if the user just clicks the window close button.

Why is the Log window open at all?

With FMP Advanced, you can use a custom menu to run a script. Attach your script to the Close Window command in the File menu. If all the layouts are set to run the [File Default] menu set, you can set that in an opening script.

If they're all set to Standard though, you might be out of luck.

You could set those script triggers in a couple hours though just grinding it through it. That's a lot shorter than forever.

Use custom menus to trap the close window command. Create a different menu set for the "main" window so that it closes all the file's open windows.

One way to close all a file's open windows is to call WindowNames() function for the current file, loop through the list of windows and close them. Something like this:


set variable [ $window_names = WindowNames( Get( FileName ) ) ]



set variable [ $window_count = ValueCount( $window_names ) ]



set variable [ $counter = 1 ]



Loop



Exit Loop If [ $window_count = $counter ]

Close Window [ GetValue( $window_names ; $counter ) ]



set variable [ $counter = $counter + 1 ]



End



Close Window [ ]

also, if attempting to close all windows, keep in mind that if the layout has fields to related, it will open the related window again as soon as you close it. When bringing a solution in for a landing, switch to a null layout.

  • Author

Thanks for all the suggestions!

I did some more testing. One "bright" idea I had was to add the script to the Log window's OnLayoutEnter script trigger. My thought was that once the Nth-1 window closes, the Log window would be activated and that trigger would fire. Sadly, it does not. Would be nice if there were a "OnWindowActivate"-type trigger.

The File/Close menuhandler is a great idea. The users are on a separate menuset with restricted options. Question: does this technique work regardless of whether the user chooses File/Close vs. just clicking the window's close widget?

Finally : I did exaggerate a bit, and if I do the brute-force approach, it's probably "dozens" of layouts not hundreds, and I could do it in under an hour. But I'd still prefer the more elegant solution if available.

Question: does this technique work regardless of whether the user chooses File/Close vs. just clicking the window's close widget?

Yes, it does work when clicking the window close icon provided by the OS.

also, if attempting to close all windows, keep in mind that if the layout has fields to related, it will open the related window again as soon as you close it. When bringing a solution in for a landing, switch to a null layout.

I think this is a good practice to get into. I recently found that it was necessary when using SuperContainer to prevent FileMaker from crashing: http://forums.filema...1#comment138579

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.