6 Replies Latest reply on Nov 13, 2014 10:12 AM by CraftICT

    Empty variable name being set by Perform Find

    CraftICT

      Summary

      Empty variable name being set by Perform Find

      Product

      FileMaker Pro

      Version

      V13/0v3

      Operating system version

      Mac OS X 10.9.5 and Windows 8.1

      Description of the issue

      Couldn't believe my eyes, but It looks as if a very old friend has returned from the dim distant past.

      If a variable used in a Perform Find [Restore] script step is empty, then the variable name is set in the find field.

      We've replicated this on both Mac and Windows versions

      Steps to reproduce the problem

      We've shared a simple file that has 2 fields and 2 scripts and populates a $test variable by Get (ActiveFieldContents) at https://www.dropbox.com/s/8pzvly6gjjd2pf3/Find%20Test.fmp12?dl=0

      The first script uses Perform Find [Restore] using $test
      The second script uses Enter Find Mode, Set Field to $test and Perform Find

      If $test is empty using the 1st script $test is entered as the search criteria (and is shown if you do a Modify Last Find)

      The second script works as expected

      Expected result

      This was a problem many versions back but was subsequently fixed

      Workaround

      The big problem is that we used to write our find requests using the 3 step approach:
      Enter Find Mode
      Set Field to variable
      Perform Find

      But because this problem didn't exist on recent versions we've taken advantage of Perform Find [Restore] but now this is breaking some existing systems. We can't afford to go back in time and rewrite all our previous solutions.

      Find_Variable.jpg

        • 1. Re: Empty variable name being set by Perform Find
          TSGal

          Andy Hibbs:

          Thank you for your post.

          According to Development, if a variable is used in a find request but is not a known variable, then it will not be expanded.  This often results in an alert complaining that no matching records are found, since it is unlikely that a variable (like $test) will match anything in the database.  This behavior is intentional to allow users to identify variables that have not yet been assigned or have a null value.

          In your case, put an IF clause around the find request.  Using your PerformFindTest script, it may now read:

          Set Variable [ $test ; Value: Get ( ActiveFieldContents ) ]
          If [ not IsEmpty ( $test ) ]
             Perform Find [ Restore ]
          End If

          -----

          The other method with entering Find Mode sets the field to the contents of the variable, so this returns a different error message.  Regardless, I can see how this can be deemed inconsistent, so I have sent these examples to Development and Testing for review.  When I receive any feedback, I will let you know.

          Even with the second example, consider using an IF clause to check the contents of $test.

          TSGal
          FileMaker, Inc.

          • 2. Re: Empty variable name being set by Perform Find
            CraftICT

            Sorry for the delay in replying and I was amazed to see that this behaviour also existed in FileMaker 11.

            Your comments make sense, but this bug was resolved somewhere between v7 and v10. More importantly, a scenario where it certainly can cause problems is when AND finds are set in Perform Find in both new files and more worryingly change the way legacy systems work.

            In the example screen shot of a failed find we had Perform Find set to:

            Find Records

            Find Test::FieldA with a criteria of $testA (set to 'Dog')

            AND Find Test::FieldB with a criteria of $testB (set to null)

            The screen shot shows that FileMaker is trying to match both 'Dog' and '$testB'. What it should be doing is finding on 'Dog' in Field A and null in Field B - this leads to a completely false result. Using Enter Find Mode using exactly the same variables results in a correct search where records containing 'Dog' are found and no search is performed in Field B.

            I do appreciate that we could overcome this by using 'If'. But surely it is a bit mad having to wrap every variable before you use it within a Find request. For instance our 2 criteria Find would have to have 4 separate Perform Finds to cover the A empty B not, B empty A not, both empty, both not empty - imagine this with 4 or 5 criteria set!

            I still maintain that this is a bug that has returned from old. We have 2 Find systems that can produce different results using the same variables - hardly consistent behaviour.

            We have solutions that have been upgraded and enhanced from original development in FileMaker 7, when we always used Enter Find Mode, Perform Find as we were aware of this bug, which was acknowledged, documented in a FileMaker update release and cured in later versions. However, once this was resolved we have used the convenient single script step of Perform Find and this behaviour could easily provide incorrect results running these systems in later versions of FileMaker.

            Looks like we're now going to have to revert to FileMaker 7 techniques!

            Thanks

            Andy

            • 3. Re: Empty variable name being set by Perform Find
              philmodjunk

              All the more reason to use the scripted find methods shown in this thread instead of using stored find requests: Scripted Find Examples

              • 4. Re: Empty variable name being set by Perform Find
                CraftICT

                Or perhaps Phil an additional category in the script steps 'Work Properly' and 'Don't Work Properly' ;-)

                • 5. Re: Empty variable name being set by Perform Find
                  philmodjunk

                  Just suggesting a work around that works right now and one I consider a better way to script finds in the first place.

                  • 6. Re: Empty variable name being set by Perform Find
                    CraftICT

                    Appreciate that Phil, as does using Enter Find Mode, Set Field and Perform Find without restore. Just didn't expect to have to worry about solutions previously written after this specific bug was solved years ago.