1 2 Previous Next 16 Replies Latest reply on Mar 1, 2017 8:28 AM by philmodjunk

    Script triggering when I don't want it to.

    phil_k

      Hi

       

      I'm creating a solution which will be primarily accessed on mobile devices but updated on a Mac.

       

      I have two script triggers, the first OnFirstWindowOpen checks for the device and directs to the appropriate 'Home' layout.

       

      The second is an OnLayoutSizeChange script which changes to a different layout when the orientation of the phone is flipped.  This trigger is applied to two layouts for the mobile device.

       

      Both scripts appear to work well except that when I open the file, the first script runs and then somehow is immediately followed by the second so instead of arriving at the home layout I end up somewhere in the middle of the solution.  I've checked the layout settings and the file options setting and both seem fine.

       

      I've not used Script Triggers before so any pointers would be appreciated.

       

      Edit:  Done some more testing and I think the problem is likely to be in the second second script which triggers because there is a window size change.  Is there any way I can restrict this script from triggering automatically or should I rewrite the script?

        • 1. Re: Script triggering when I don't want it to.
          dale_allyn

          Without seeing your scripts and having more information it's difficult to pinpoint. One thing to consider is wrapping your "orientation" script (second script you mention) in a IF statement to check device type before triggering the OnLayoutSizeChange event. E.g. IF device is iPad or iPhone do this stuff; Else Exit script (or go to a different layout, etc.)...

           

          If your first script is working as desired I think you have the needed script steps to draw from for determining device type.

           

          IF [ Get ( Device ) = 4 ] //Indicates iPhone

           

          //Do something here for iPhone

           

          Else

               Exit Script or Go to Layout X, etc.

          End IF

          • 2. Re: Script triggering when I don't want it to.
            coherentkris

            Actions that cause the OnLayoutSizeChange script trigger to execute | FileMaker

             

            The important thing about the actions that cause the trigger is the "When a window is first opened"

            part.

            You will have to figure out a way to allow the trigger to process on the layout in question when you want it to or redesign the layouts to leverage object anchors so don't need separate layouts for each orientation.

            This is a post process trigger so it cant be aborted with return = true.

            • 3. Re: Script triggering when I don't want it to.
              phil_k

              Thanks coherentKris, that reference seems to supply the answer.  The OnLayoutSizeChange triggers automatically when the file is opened.  Guess I'll have to look at a different method of triggering.

              • 4. Re: Script triggering when I don't want it to.
                coherentkris

                OnLayoutSizeChange is specifically attached to a layout. If you dont go that layout on first open the trigger wont fire.

                • 5. Re: Script triggering when I don't want it to.
                  phil_k

                  But it does. My script is specifically attached to that layout but reading the article that you posted a link to, one of the actions that triggers the script is the opening of the file.

                   

                  OnLayoutSizeChange script trigger that triggers a script to run after a layout or window has changed size as a result of the following:

                  Product

                  Action

                  FileMaker Go
                  • Rotating the iOS device
                  • Hiding or showing the status toolbar
                  • When a window is first opened
                  FileMaker Pro
                  FileMaker WebDirect
                  • User interaction
                  • Script / script step
                  • Hiding or showing the status toolbar via menu command, shortcut or script step
                  • Hiding or showing the formatting bar via menu command, shortcut, or script step
                  • When a window is first opened

                   

                   

                  So what is happening is that the original Get Device script runs, followed immediately by the OnLayoutSizeChange script because in effect the layout is changing size.

                   

                  One the file is open the OnLayoutSizeChange script performs normally.  Perhaps I might get this script to call the opening script after it has been run, which might then return me to the intended opening screen but that seems a bit messy.

                   

                  Interesting though, I have another OnLayoutSizeChange script attached to another pair of layouts and this does not run at startup.

                  • 6. Re: Script triggering when I don't want it to.
                    wimdecorte

                    This is a great blog post with an excellent demo file that demonstrates how events fire in order and when.  It's a great sandbox to get to know all the triggers.  If you are uncertain which events will fire when you do something, just try it in the demo file.

                     

                    FileMaker 14 Script Triggers - Soliant Consulting

                    2 of 2 people found this helpful
                    • 8. Re: Script triggering when I don't want it to.
                      dale_allyn

                      In my applications which support iOS devices, I determine the device type on file open and send the user to the appropriate layout (for Desktop, iPad or iPhone). Then, from this device-appropriate layout I run any scripts for that environment, and navigation to other layouts stays within layouts for that specific device type. This is where I would put your orientation trigger. YMMV

                      • 9. Re: Script triggering when I don't want it to.
                        phil_k

                        That's sort of what I'm doing.  I have the script for determining the device run at startup and it works fine.

                         

                        The second script is designed to change between a list view and a form view on the phone so that in vertical mode the form shows and in horizontal the list view.  Again it works fine once everything is open and running.  However the action of opening the file triggers the OnLayoutSizeChange script whether I want it to or not and independent of any layout that it is attached to.

                         

                        I've tried deleting the second script and everything then works fine, the layouts are displayed according to the device.  I just now need to find a different way to script the layout change when the device is rotated.

                        • 10. Re: Script triggering when I don't want it to.
                          dale_allyn

                          If the OnLayoutSizeChange script trigger is only on the layouts specifically designed for mobile, you should be able to isolate this behavior. Unless you're applying to the first mobile window that opens. Then you'll have the conflict you're describing. In my case(s) each device type has launch page that allows user to determine their next operation, i.e. go to Sales, Inventory, Customers, etc.; or it's controlled by account name or permission set (e.g. Customer Service vs Laboratory, etc.). In my cases I don't use the orientation resize on this launch layout because it's mostly iPhone in one case and portrait mode works best for that step. Then it can be used on the other layouts.

                           

                          The key is that you'll want to apply that trigger to layouts after the first window opens. Maybe I'm missing something in your use case.

                          • 11. Re: Script triggering when I don't want it to.
                            philmodjunk

                            Sounds like your second script needs to use get ( WindowOrientation ) to identify whether you are in portrait or landscape before altering the view.

                            • 12. Re: Script triggering when I don't want it to.
                              phil_k

                              The solution I'm working on is designed as a reference tool and so user interaction is kept to a minimum.  There is no editable data in the mobile version.  I'm using the OnLayoutSizeChange script trigger to offer users an alternative view of the data, for example a search feature in vertical mode and a list view in horizontal mode.

                               

                              "If the OnLayoutSizeChange script trigger is only on the layouts specifically designed for mobile,"

                               

                              It is.

                               

                              "In my case(s) each device type has launch page that allows user to determine their next operation, i.e. go to Sales, Inventory, Customers, etc.;"

                               

                              I have similar.  In the case of this solution there is a 'home' screen for the mobile device that has a series of buttons that go to different parts of the solution.  The mobile version is 'read only' so there are no login details required, all layout tools etc are locked so that the user has no access.

                               

                              If the startup script detects that it is a Mac then a different screen is loaded to enable editing.

                               

                              But I'm struggling to find a way of preventing the OnLayoutSizeChange script triggering at startup because (as the screenshot above shows) in both FileMaker Pro and FileMaker Go this script action is triggered automatically when the file is opened because in effect this does change the layout size.

                               

                              Unless I'm missing something too.

                              • 13. Re: Script triggering when I don't want it to.
                                phil_k

                                Thanks. Yes, it already does.  There isn't a problem with the script, the problem is preventing it triggering at start-up.

                                • 14. Re: Script triggering when I don't want it to.
                                  philmodjunk

                                  Yet if it checks the orientation, the fact that it triggers at start up shouldn't be a problem as it is then selecting the correct view for you.

                                  1 2 Previous Next