4 Replies Latest reply on Dec 30, 2015 6:35 AM by MJMWeb

    FileMaker WebDirect Script Triggers Only Once


      I have two layouts, Resources and Affiliates. Resources has a sub-summary and thus needs to be sorted as soon as the user enters the view. On FileMaker Pro, this isn't an issue. I can switch back and forth to it innumerable times from other layouts and the data displays just fine. However on WebDirect the script will only fire upon entering the view for the first time. If I switch to another layout and back again the sorting script doesn't fire. I've tried attaching it to OnEnterLayout and OnRecordLoad but the same thing happens each time. It's a simple script:


      1 Show All Records

      2 Sort Records by Field [Ascending;Resources::techName]


      I know WebDirect has issues with scripting, but that shouldn't affect this kind of script as it has nothing to do with committing records.

        • 1. Re: FileMaker WebDirect Script Triggers Only Once
          I know WebDirect has issues with scripting

          WebDirect has differences in scripting. I wouldn't call them issues. That's like saying a FileMaker Server scheduled script has issues with scripting, when in reality, it's just an entirely different context.

          I think you may need to use "sort records" instead of "sort records by field". There are a number of nuances with the sort records by field script that make it less reliable than "sort records" due to the latter script step's requirement for a context. Try it with sort records instead.

          One of the keys to successful WebDirect development is to think of your scripts and triggers like you would for something run "blind" to the client. This means that your navigation and scripting should perform as if the client wasn't looking at it. Why? Because filemaker server, NOT the client, is what is doing all of the work in terms of drawing, evaluating and returning data.


          How do you know it isn't firing?, have you added something like a custom dialog to a script that didn't show up when you switched layouts? It may just not perform as you would expect it due to the context difference of WebDirect.

          As a test, I made a quick OnLayoutEnter script for two unrelated layouts, and a button that navigates from one to the other on both layouts. My script had:

          Show All Records

          Sort Records [ specified sort order ; no dialog ]

          Show Custom Dialog [ "sorted ok" ]

          From every possible way of getting to either layout, that script fired every time. I even manually unsorted the found set, left and return to the layout to find that it had indeed performed the sort.

          • 2. Re: FileMaker WebDirect Script Triggers Only Once

            Well, it is running after all. I added unchecked "Perform without dialog" and the sorting dialog is showing up. It's also sorting it correctly. For some reason, however, the sort doesn't work without the dialog, at least not on a trigger like OnEnterLayout. I did switch it to Sort Records instead of Sort Records by Field, and that did not fix the issue. I did as you did and added a message dialog box to the end of the script. It does pop up and the records still don't sort. It should be mentioned, that after it loads if I set the script to a button or I just call the script from the menu, the sort works just fine, so it is possible it's something to do with the way it's triggering.


            Any of that give any clues as to what the issue might be?

            • 3. Re: FileMaker WebDirect Script Triggers Only Once

              Probably the found set or sort order hasn't actually changed, so filemaker doesn't know that the screen needs to be redrawn over it's last state.


              try adding:

              scroll window


              to the trigger script to see if scrolling to the top will show the sort.


              Also why is the sort changing at all? when you leave and come back, both your found set and sort order should be retained right? are you checking the "keep records in sorted order" option?


              It might be behavior specific to your solution. You've gone through and made sure that everything is WebDirect compatible in the script workspace correct?

              • 4. Re: FileMaker WebDirect Script Triggers Only Once

                I tried your suggestions. Here are the results:


                1. "Keep records in sorted order" was checked this entire time. I even tried it without the option. Still no change.


                2. I added the window scroll. I should mention that the graphs in the grand summary are showing up just fine. It's the sub-summary section that isn't showing up, so when I scrolled to the top it didn't change anything.


                3. For the Script Workspace, I know of no way to ensure it's WebDirect compatible other than to select WebDirect under View -> Compatibility. It was previously under "All" so I believe it is compatible. If there's something else I'm missing here I'd love to try that. I should also mention that "Scroll Window" is grayed out when I select WebDirect compatiblity.


                4. Your window scroll suggestion gave me an idea. I added "Refresh Window" to the end of the script, and now the sub-summary section shows up as it should. It also loads the visual theme which it also wasn't doing before (edit: it's still not changing the theme consistently), even when running the script proper. Since it was your idea that led me to the solution, I will give you credit for the correct answer. In case future people come across this page with a similar issue, could you reply to this comment suggesting that they try "Refresh Window" so I can say it's the correct answer and not have to have people search through this whole thread to find the solution? Thanks.