4 Replies Latest reply on Jul 5, 2012 2:25 PM by CodyRomphf

    Perform Find Syntax with Variables

    CodyRomphf

      Title

      Perform Find Syntax with Variables

      Post

      What I am trying to do is build a script that will perform a find on a table and display all relevant results. Everything is structured correctly I just do not understand the required syntax for the "Perform Find" step. 

      What I have: A table called Citations and a table called Extractions which are related via my RefID.

      What I have tried: I have tested the find by using a known RefID number that would find some results. (Eg the number 2 where my syntax was Citations::RefID = 2) And the find works perfectly. However I would like to be able to make the criteria dynamic so it is actually useful. The way I understand it is that I should be able to say Citations::RefID = Extractions::RefID . Unfortunately this does not work. I did some reasearch and I learned that I needed a $ sign before variables but I have tried this as well and it does not work. 

      I am sure this is just a simple syntax error but I cant find anywhere that explains the correct syntax. If someone could shed some light on the correct wording necessary that would be great. Thanks!

      Cody

        • 1. Re: Perform Find Syntax with Variables
          philmodjunk

          What are you trying to find? (I can read your post more than one way). Citations or extractions? How would the script know which RefID value to use in the script?

          Are you on a citations layout and want to find all Extractions records with the same RefID as the current Citations record?

          If so,

          Set variable [$RefID ; value: Citations::RefID]
          Go to Layout [Extractions (Extractions)]
          Enter find mode[] //clear the pause check box
          Set Field [Extractions::RefID ; $RefID]
          Set Error Capture [on]
          Perform Find []

          But it's also possible to do this with no find performed at all:

          Go To Related Record [Show only related records; From table: Extractions; Using layout: "Extractions" (Extractions)]

          This script will find all related extractions record and pull them up on your Extractions layout or will leave you on the current Ciations layout if there are no matching records in Extractions.


          • 2. Re: Perform Find Syntax with Variables
            CodyRomphf

            So you are exactly correct I am on the citations layout and wanting to find all the extractions that are associated with the same RefID as the current citations record.

            Ok so I have entered exactly what you have there and it works perfectly now! Thank you very much! Would you mind explaining what exactly those steps are doing. I have an idea but I want to make sure I understand how it works in case I come up against something like this is the the future. Thanks again for your help.

            Best regards,

            Cody

            • 3. Re: Perform Find Syntax with Variables
              philmodjunk

              And here's another option to consider: If you placed a portal to Extractions on the Citations layout, you coud see a list of all extractions for that citations and, if you permit it, to edit/add/remove them.

              The step by step explanation. This script mirrors the steps you'd take to perform a manual find.

              Set Variable   -- assigns a value to a variable. If the variable does not already exixt, it is created by this script step. $Variables with a single dollar sign are variables that exist only with in the script and for only as long as the script is executing. $$Variable names with two dollar signs are global variables that will exist and be accessible from any script on any layout in your file for as long as the file remains open.

              Enter find mode[]  this does the same as clicking the Find button in the tool bar. It sets a window mode where you get what looks like an empty record in order to enter search criteria.

              Set Field enters data into a specified field. When you are in find mode like in this script, all normal fields are blank just like you see happen when you select find mode manually, but data in a variable or a global field can be accessed and copied into a field to create search criteria.

              Set Error Capture [on] This step disables the FileMaker built in error messaging system for most errors that would otherwise interrupt your script with an error message. In a scripted find, not finding any records would produce such an error message and it's options are not really appropriate for a scripted find, so I included this step to keep such an occurrence from interrupting the script if no records are found.

              Perform find[] This is the scripted equivalent of clicking Perform Find while in Find mode.

              About the empty brackets with Perform Find and Enter Find Mode:

              When you add either of these steps, there's a specify button that you can click to set up your search criteria directly within that script step. This may seem like a better way to go instead of using what could be a fairly long list of set field steps to set up your scripted find, but I almost never use those options for the following two reasons:

              1) You can't set up a calculation to compute what criteria is to be entered. Often, I need criteria such as "<" & Get ( CurrentDate ) + 30 and that can't be entered as part of the Perform Find or Enter Find steps.

              You can refer to a variable, so it does work for this case, but:

              2) This hides the criteria away inside the script step and you have to double click the step or click the specify button to open up the dialog where you can see what criteria was specified. This makes it harder to quickly review a script--say a couple of months from now--to see what criteria is used when the find is performed.

              • 4. Re: Perform Find Syntax with Variables
                CodyRomphf

                Thank you very much for the clarification. You have no idea how much it helps having the script steps defined. Often I have no idea what they do without putting extensive time playing around with them until I have a vague understanding. I just wanted to say thanks again for all your help with the problem I was experiencing.

                 

                Best regards,

                 

                Cody