7 Replies Latest reply on Oct 17, 2016 12:03 AM by user17152

    Questions about portal filtering using global variables

    user17152

      I’m trying to build a “Favorites” view for my solution and am having issues with a filtered portal.  I’ve given my users the ability to “favorite” pretty much every record type in the database.  Every time a user marks a record as favorite, a record is created in the Favorites table with the username, record type (ie: contact, project, etc), and the record id.  The user can view a list of favorites and jump to the appropriate record.  All of this works fine.

       

      By default the user’s Favorites list shows all favorites.  There is a global pop-up menu with all record types that triggers a Find if the user wants to focus on a specific type (ie: all favorite contacts only).  No problems here.

       

      I then decided to try something different.  Instead of the Favorites list being a list view of the Favorites table, I decided to make it a portal via a relationship from User to Favorite, matching username to username.  I’m trying to create a left-side source panel style interface, so I have a list of all record types on the left and a portal showing all favorites on the right.

       

      Since the favorites list could potentially be open in more than one window at a time, I wanted to see if it was possible to filter on a dynamically created variable.  When the user opens the favorites list (changes layout, via a script), a variable is created called $$favorite_WINDOWNAME.  Since the window names in my solution are always unique, I figured I could store my portal filter key here.  And since each window receives its own unique variable, I should be able to have different filters engaged in each window.

       

      So everything works, except the portal filter.  The portal is filtered via an Evaluate function:

       

      Case (

       

        Evaluate ( "$$favorites_" & Substitute ( Get ( WindowName ); " "; "" ) ) = "showall"; 1;

       

        Evaluate ( "$$favorites_" & Substitute ( Get ( WindowName ); " "; "" ) ) ≠  "showall" and

        Evaluate ( "$$favorites_" & Substitute ( Get ( WindowName ); " "; "" ) ) = user_favorites::favorite_item_record_type; 1;

       

        0

       

      )

       

      And when I say the portal filter does not work, that’s not entirely true.  It works, but every window’s portal is updated when a selection is made in any window, despite the fact that each window’s portal should be filtered via a different, unique variable.  I wanted to try to make this work using filters and unique variables rather than a global field since I knew that would update every view.  Has anyone tried to do something like this?  I’m assuming it’s not possible?

       

      What I find interesting is that the object hiding function works fine using the above Evaluate statement.  I can view the same Favorites layout in multiple windows and have different objects hide in each window based on the value in the unique $$_favorites_WINDOWNAME variable.

       

      Any and all thoughts appreciated.  Thanks!

        • 1. Re: Questions about portal filtering using global variables
          user17152

          A little more information...

           

          After setting the filter variable, I was using a Refresh Portal step to refresh the contents of the portal.  Out of curiosity, I changed it from Refresh Portal to Refresh Window.  That didn't work.  The portal in the active window did not update, nor did the portal in any other window.  Then I turned the Flush options on and only the portal in the active window updated its contents!  So it works.

           

          Can one of you experts explain what's going on here?  I'm glad it works the way I want it to, but I'd like to know why.  Thanks!

          • 2. Re: Questions about portal filtering using global variables
            user19752

            As you wrote, the "Refresh portal" script step is described as "Use Refresh Portal when a global field used in the portal’s filter calculation has been modified."

            So I'm not sure but it looks if there is no global field in filter calculation, it is not the case for use it.

            How about adding dummy global field in the calculation? But it can be no matter if the field is not changed.

             

            Your calculation may be able to shorter,

             

            Case (

              Evaluate ( "$$favorites_" & Substitute ( Get ( WindowName ); " "; "" ) ) = "showall"

            or

              Evaluate ( "$$favorites_" & Substitute ( Get ( WindowName ); " "; "" ) ) = user_favorites::favorite_item_record_type

            )

             

            using Let() for Evaluate() once may be more better.

            • 3. Re: Questions about portal filtering using global variables
              user17152

              Agreed about the formula. What's interesting is that my filter does not reference a global field. The field referenced is a regular text field. The variable is a global variable and each window has a unique variable.  How come Refresh Portal causes every portal to refresh despite the fact that the filter is written to take the unique window variable into account?

              • 4. Re: Questions about portal filtering using global variables
                philmodjunk

                How come Refresh Portal causes every portal to refresh despite the fact that the filter is written to take the unique window variable into account?

                 

                I'm a bit surprised too, but don't they all have the same object name and that's what Refresh Portal references to know which portal is refreshed? (I'd think that this would be restricted to the window that has the focus, but apparently not.)

                 

                You might report this over in report an issue as a possible bug and see if this is expected behavior or not.

                1 of 1 people found this helpful
                • 5. Re: Questions about portal filtering using global variables
                  user17152

                  I think you and I are on the same page.  Yes, the portal name is the same in each window, but shouldn't the refresh command pertain to the active window only?  Furthermore, the filter references the window-specific variable when refreshing.  Even if the refresh command caused multiple windows to refresh, shouldn't each window use its own variable, thus resulting in different filtered results in each window?  That's the part I really don't understand and what makes me think this is a bug of some kind.

                   

                  Because the filter uses a different variable in each window, the results should only be the same if each window's variable contains the same value.  What happens for me is that each window updates using the active window's variable when the refresh portal step runs.  Yet if I use a Refresh Window w/ flush step, everything works as expected.

                   

                  I really wish Filemaker had window-specific global fields and variables.  Anyway, yes, I am going to report it.  I realize I'm probably using variables and portal filters in a way they might not have intended, yet I think my logic is sound and the fact that it works with refresh window but not refresh portal suggests a bug in my opinion.  Thanks for your feedback.  Much appreciated.

                  • 6. Re: Questions about portal filtering using global variables
                    user19752

                    I think your problem is Get(WindowName) does not return each window's name or active windows'name. It "Returns the name of the window on which the script is acting", so all window would have same value.

                    2 of 2 people found this helpful
                    • 7. Re: Questions about portal filtering using global variables
                      user17152

                      Ah, very interesting.  So why do you suppose Refresh Portal and Refresh Window w/ flush produce different results?