We have a layout in our FileMaker database with an OnLayoutExit script trigger that checks if the user left required fields empty. However, as part of standard use of the layout another script is called that populates fields across several tables. To do this the script performs several
Go To Layout() function calls. This is triggering the OnLayoutExit script trigger from the original layout. The user is unlikely to have filled out the required fields by the time this script is called. When this script is finished, it returns back to the original layout, so the empty fields are not an issue for us. However, our OnLayoutExit script is warning the user of the empty fields.
I'm curious if there is a way to differentiate between the user switching layouts and a script switching layouts.
A simple solution could be not to have the script leave the layout. Instead of switching to another layout, open a new window with the target layout, do what needs to be done, then close the new window.
To answer your question as asked: leaving a layout is leaving a layout, no matter how it's done. The only way to distinguish between the cases is to have your triggered script look at the contents of a field/variable/script parameter and adjust its action accordingly.
Another option is to enter Find mode before leaving the layout (assuming the trigger is only enabled in Browse mode). But that could be rather confusing when you review the script at a later time.