3 Replies Latest reply on Feb 12, 2013 9:03 AM by flukey

    Performing a find with a global variable.

    pedantic

      My apologies for this very basic question, but I am missing something in the documentation because when I use a global variable, my find does not work. There may be a monkey wrench thrown in the works because I am performing a find on MySQL tables. AFAIK the MySQL tables are properly integrated into Filemaker 11 using ODBC. At least when I go to their layouts I see plenty of data.

       

      Here's the code:

       

      In script A I have this line:

       

      set variable [$$JobKey, Value:MySQL_Jobs::nKey] // $$JobKey is set to 20993

       

      Further on down the script I have this line:

       

      Perform script [B]

       

      In script B I have the following line:

       

      Perform Find [Restore]

       

      In the list of finds I have only one and it looks like this:

       

      Action: Find Records

       

      Criterion: MySQL_ODSubs::nJob_Key == $$JobKey // $$JobKey is assigned the value of 20993...I verified this in the Data Viewer.

       

      This Perform find statement results in no records being returned. However if I chage the Criterion statement to this:

       

      Criterion: MySQL_ODSubs::nJob_Key == 20993

       

      I get the expected find list of two records.

       

      Is there a special trick for handling variables in a Find statement?

       

      TIA!

       

      John

        • 1. Re: Performing a find with a global variable.
          Mike_Mitchell

          This won't work because FileMaker stored the value "$$JobKey" in the Find Request. (A quirk of how stored Find Requests work.)

           

          In order to do this, you'll need to set it dynamically:

           

          Enter Find Mode

          Set Field [ MySQL_ODSubs::nJob_Key ; $$JobKey ]

          Perform Find [ ]

           

          HTH

           

          Mike

          • 2. Re: Performing a find with a global variable.
            pedantic

            Thanks MIke.  That's exactly what I needed.  Happy Phat Tuesday!

             

            R,

            John

            • 3. Re: Performing a find with a global variable.
              flukey

              Alternatively you could do the following and avoid having to switch to find mode and go to a find layout:

               

                    set variable [$$JobKey, Value: "==" & MySQL_Jobs::nKey] // $$JobKey is set to ==20993

               

              In your PerformFind use

               

                    Criterion: MySQL_ODSubs::nJob_Key       from left table and enter       $$JobKey      on right side.

               

              i.e. do not enter any symbols or anything other than the global variable on the right side.

               

              This technique works for many finds where using the inserted symbols and then a variable does not work.  E.g. it works for a date range, simply

               

                    set variable [$DateRange, Value: StartDate & ".." & EndDate] where StartDate and EndDate could be fields or some other variable.