7 Replies Latest reply on Jun 27, 2011 1:24 PM by wadef

    Sort Script Works from Button, but not from Trigger

    wadef

      Title

      Sort Script Works from Button, but not from Trigger

      Post

      I'm running FMP 11.0v3 on a Mac mini, OSX 10.6.7.  I have prior experience as an assembly language & Fortran programmer and have been working on this one database (my first) for over a year.  So I guess I'm slightly more than a novice.  I'm generating an investment management database to replace my useless Quicken package.  Most of it is working with no problem.

      However, I have 3 layouts, all based on the same table and each including a sub-total field for each grouping and a % field .  I have 3 buttons on each layout which call one of 3 scripts to go to one of the other layouts and sort it according to the view I want for that layout.  (e.g. by accounts for one, by security for another, by asset allocation type for the 3rd). This works well and the sub-total and % fields are correctly displayed each time a button to switch to a different layout is clicked.

      As I would like to add 2 more layouts, each with it's own sort, I tried putting in a pull-down field with Account/Security/Asset Alloc plus 2 other values and I set up a trigger using OnObjectModify to call a script that checks the value and calls the exact same subscript as was associated with each button.

      Much to my amazement, when FMP switches to a new layout from the pull-down script, the subtotals and % do not display.  If I put a pause/resume statement in my script as a debug tool, the totals and % DO display!!!!!!

      I'm confused.  I've tried virtually every combination of parameters for the sort, but nothing seems to resolve this issue (other than putting in the pause).  As I really don't want to populate half my screen with buttons for selecting each layout, I'd really like to know what I've done wrong.

      Thanks for any help or suggestions you can give me.

      Wade

        • 1. Re: Sort Script Works from Button, but not from Trigger
          robdownunder
          Do you need a commit step in the trigger script? I've had issues using dropdowns  rather than buttons and needed to commit the change to the dropdown field to make other features work.
          • 2. Re: Sort Script Works from Button, but not from Trigger
            wadef

            I just tried it now - no difference.  I'm not sure what a commit step would do in this case anyway.  My problem isn't with getting the pull-down field from the record - I get that OK and call the appropriate sub script to do the desired sort.  Even the sort works - but the sub totals don't get displayed unless I do a pause.  (I even tried doing a commit after the sort.)

            • 3. Re: Sort Script Works from Button, but not from Trigger
              philmodjunk

              It's hard to say exactly without knowing more about how you've designed your layouts and the methods you've used for producing the totals and % values.

              Since pause fixes the issue, you might try replacing that pause step with a refresh window step. (Try it with and without the "Flush cached join results" option)

              • 4. Re: Sort Script Works from Button, but not from Trigger
                wadef

                Hmm, it's getting even stranger.  I did a refresh window (both with & without 'Flush cached join results') and it will display the sub-summary result but ONLY for the result that's in the window view at the time (i.e. if I scroll up or down, sub-summaries in those parts of the window are still not displayed).


                My layout is a pretty standard one, with two summary fields in the sub-summary portion of the layout:one called 'Sub_Summary' and set to 'Total of Value' in the table definition for a (sub) summary field sorted by 'Account_Name' (ascending order), plus a second summary field called 'Percent_of_Holdings' set to 'Fraction of Total Value' in the table definition.  In addition there is a 'Trailing Grand Summary' part to the layout based on a field named 'summary'.  The 3 layouts in question are all defined with the same Associated Table ('Portfolio Summary) - just sorted by different fields (each sort has 2 sort fields - Account_Name and Security_Name for one; Security_Name and Account_Name for the second; and Asset_Alloc_Type and Security_ID for the third).

                I have made some experimental changes to the sort (I'm losing track of what combinations I've tried!!) and have now got to the point where I get one of the two summary fields displayed consistently (the field called 'Sub_Summary' that is set to 'Total of Value') but the second one (called 'Percent_of_Holdings', set to 'ration of Total Value') is still showing a blank.  But now the Grand Total is sometimes blank in one of the layouts.


                Even with these changes, as I said in my original post, when the script(s) is (are) called from a button, it works consistently, e.g. the script "View Portfolio by Accounts Button" is simply:
                GoTo Layout [View Portfolio by Account]
                Sort (by Account_Name & Security_Name)
                Exit


                If I call the exact same subscript from a routine that's triggered by OnObjectModify on a field containing a pull-down list (with 'Account', 'Security', and 'Asset Allocation' as the pull-down list) with the following code, it doesn't display the % sub-summaries & inconsistently displays (or not) the Grand Total. That script is:


                If [Portfolio Summary::G_View_By = "Account"]
                    Perform Script ["View Portfolio by Accounts Button"]
                    Refresh Window [Flush cached join results]  (doesn't make a difference if this step is included or not, except as noted in 1st para above)
                End If (and then go on to check for the other possible fields (to verify that the subsequent If statements aren't the cause, I've done this with just the one IF statement and nothing following and still get the same problem)

                • 5. Re: Sort Script Works from Button, but not from Trigger
                  wadef

                  Sorry, " 'Percent_of_Holdings', set to 'ration of Total Value' "  should read " 'Percent_of_Holdings', set to 'Fraction of Total Value' "

                  Wade

                  • 6. Re: Sort Script Works from Button, but not from Trigger
                    philmodjunk

                    Is the layout where you have your button and the layout where you have the dropdown w/script trigger the same layout?

                    If not, do both layouts list the same table occurrence in "Show Records From" in Layout setup?

                    Try changing this to OnObjectExit instead of OnObjectModify. It may make no difference to the existing issue, but drop down lists permit the user to type data into the field and the OnObjectModify trigger will "fire" with every keystroke where OnObjectExit will not until you finish entering/selecting data and exit the field. (OnObjectModify is a good choice for pop up menus, radio buttons and/or check boxes.)

                     

                    • 7. Re: Sort Script Works from Button, but not from Trigger
                      wadef

                      Wow!  Phil, you are a genius!Smile  It works!

                      I thought I had tried that particular variant, but obviously I didn't. All 3 layouts now work from the pull-down.

                      I guess the script & sort was getting executed multiple times and confusing the issue.

                      Thanks for the help.

                      Wade