1 2 Previous Next 25 Replies Latest reply on Jul 21, 2017 3:50 AM by fmenquiry

    Using variables in FIND

    fmenquiry

      I have written a script which includes 2 FINDs - the first finds a group of records for a product which I need for a base calculation of their cost. The second finds the same group of records but derestricts the product characteristics. It would be nice not to have to enter the products twice. However, if I set global variables to do this after the first find and then use Set Field in the second FIND to the global variables I want to re-use it doesn't work. Will it even work? Maybe I need to use global fields instead?

        • 1. Re: Using variables in FIND
          keywords

          It is really not clear, at least to me, what the true nature of your query is; perhaps you should post your script as it would help us to help you. You should also indicate what version of FM you are using and what platform and OS.

          That said, let me have a stab. Your script probably should include the following steps:

          Set variable – // here you would set the Find value(s) you want to use. It can be a local variable ($) if it is only used within this script, but if you need to reuse it in another script you should make it a global variable ($$)

          Enter Find Mode

          Set field – // use the variable(s) as your find criteria

          Perform Find – // make sure you switch of the restore setting

          Exit script

           

          It sounds as if your second Find may be a Constrain or Extend instead of a regular find. If so, set your second script accordingly.

          • 2. Re: Using variables in FIND
            fmenquiry

            I think I see where the problem is - this was helpful. In my second FIND I have included the step Enter Find Mode and changed a couple of the parameters (but not, obviously, the ones I wanted to continue with). So, also, RESTORE is on and I suppose this is killing the variables I have defined at the beginning of the script. I suppose the only way to do this is to write the variables to global fields and pick these up?

            • 3. Re: Using variables in FIND
              keywords

              1.     The Restore seeing means you actually save the Find criteria inside the Perform Find script step. This makes it harder to modify and troubleshoot, and much harder to review and understand on this forum (as many users have/will point out). The method I described of Enter Find Mode/Set Field/Perform Find is more explicit and much easier all round.

              2.     As you now suspect, if you leave Restore set, this will override any Set Field criteria you include before it in the script.

              3.     You don't need to "write the variables to global fields". Write them as global variables will have the same effect and obviate the need for extra global fields.

              • 4. Re: Using variables in FIND
                fmenquiry

                wow - that was quick. Thank you. I will try that. This is the script anyway using global fields but when it performs the second find instead of the contents of the fields gObject I get "gObject"! :

                 

                Enter Find Mode [ Specified Find Requests: Find Records ; Criteria: Table::Objects : “==” AND Table::

                format: “75cl”]

                [ Restore; Pause ]

                Perform Find [ ]

                Set Field [ Table::gObjects ; Table::Objects ]

                Set Field [ Table::gYear ; Table::Year ]

                Sort Records [ Restore; No dialog ]

                Set Variable [ $$cost; Value:GetSummary(Table::sAverage_price;Table::format) ]

                Set Field [ Table::gAverage_cost; $$cost ]

                Go to Layout [ “Layout” (Table) ]

                Go to Layout [ “Find” (Table) ]

                Enter Find Mode [ Specified Find Requests: Find Records ; Criteria: Table::Objects : “==gObjects” AND

                Table::Year : “gYear”]

                [ Restore ]

                Perform Find [ ]

                Sort Records [ ]

                [ No dialog ]

                Go to Layout [ “Layout” (Table) ]

                Enter Preview Mode

                • 5. Re: Using variables in FIND
                  keywords

                  Some comments on your script (//—…ff):

                  Enter Find Mode [ Specified Find Requests: Find Records ; Criteria: Table::Objects : “==” AND Table::

                  format: “75cl”]

                  [ Restore; Pause ]  (//—why do you use restore settings here? be consistent)

                  Perform Find [ ]

                  Set Field [ Table::gObjects ; Table::Objects ]

                  Set Field [ Table::gYear ; Table::Year ]

                  Sort Records [ Restore; No dialog ]

                  Set Variable [ $$cost; Value:GetSummary(Table::sAverage_price;Table::format) ]

                  Set Field [ Table::gAverage_cost; $$cost ]

                  Go to Layout [ “Layout” (Table) ]  (//—there is no point in this step since you immediately override it)

                  Go to Layout [ “Find” (Table) ]

                  Enter Find Mode [ Specified Find Requests: Find Records ; Criteria: Table::Objects : “==gObjects” AND

                  Table::Year : “gYear”]  (//—try using just gObjects—no quotes, no ==, and see if that helps)

                  [ Restore ]  (//—as above: why do you use restore settings here? be consistent)

                  Perform Find [ ]

                  Sort Records [ ]

                  [ No dialog ]

                  Go to Layout [ “Layout” (Table) ]

                  Enter Preview Mode

                  • 6. Re: Using variables in FIND
                    fmenquiry

                    "[ Restore; Pause ]  (//—why do you use restore settings here? be consistent)"

                     

                    I have to since I am adding some pre-filled field data eg date, "==" to narrow the find etc.

                     

                    "

                    Go to Layout [ “Layout” (Table) ]  (//—there is no point in this step since you immediately override it)

                    Go to Layout [ “Find” (Table) ]" Actually don't need either of these since I am not actually entering any data.

                     

                    "

                    Enter Find Mode [ Specified Find Requests: Find Records ; Criteria: Table::Objects : “==gObjects” AND

                    Table::Year : “gYear”]  (//—try using just gObjects—no quotes, no ==, and see if that helps)"

                    Not actually in quotes..

                    So, not working but thanks anyway. Just have to rekey the data everytime.

                     

                     

                    • 7. Re: Using variables in FIND
                      philmodjunk

                      When you put "gYear" in as Find criteria, you are specifying the text "gYear" instead of the value of that field. You cannot reference the value of a global field in stored Find criteria. If you use set field to specify your criteria, you can refer to your global field's value in order to enter its data as a find criterion.

                       

                      Contrary to what you have posted, every single criterion in your script can be specified with set field steps. None of them have to be stored.

                      • 8. Re: Using variables in FIND
                        fmenquiry

                        Afraid if I set field in wrong place it will overwrite the field in my entire db.

                        • 9. Re: Using variables in FIND
                          philmodjunk

                          Not when you are in Find Mode.

                           

                          Even in Browse Mode, it would modify the value for a single record--not your entire DB.

                           

                          And you are already using this method. I am simply suggesting that you use it for all your criteria instead of mixing and matching.

                          • 10. Re: Using variables in FIND
                            fmenquiry

                            How do you set a field simply to have == in it? This is one of the things I was doing when I specified Find Mode. (by the way FMP12.5 Adv)

                            • 11. Re: Using variables in FIND
                              philmodjunk

                              Set Field [ YourTable::Field ; "==" ]

                              • 12. Re: Using variables in FIND
                                fmenquiry

                                So, thank you for your input but none of it quite works and I suspect I'm trying top do something FM can't really cope with (finally). If I might one last time, let me go back to first principles...

                                 

                                I want to key in a find which looks for only that product so I must use == otherwise other products come up. Find Mode works well because I can pre-populate the fields with, for example, == and other common data I want to use eg dates. I want to use these products for another find and, ideally, which is what I am really trying to arrive at without having to re-key the data for the product in the first place.

                                 

                                None of what we have above works... any last suggestions (for which I am very grateful) and I will explore and report.

                                • 13. Re: Using variables in FIND
                                  keywords

                                  Re: "I suspect I'm trying top do something FM can't really cope with"

                                  I doubt it. Remember that anything you can do manually can also be done via a properly constructed script. I suggest you step through the process manually, writing down every single step you take. When you've done that turn that set of steps into a script (and by the way, if in a script you want to use ==, remember that this is treated by FM as a text object so must be in quotes. In combination with contents of a global field you calc would look like this:  "==" & tableName::gFieldName).

                                  • 14. Re: Using variables in FIND
                                    BruceRobertson
                                    None of what we have above works...

                                    Addition works. Subtraction works. Differential calculus works. Training a dog to fetch; that also works. The script procedures provided by Keywords work.

                                    Whether you can do things that require common; well understood; and actually rather ancient skills, is the more critical question.

                                     

                                    Along with the problem of providing a clear and grammatically decipherable problem statement.

                                    What are you trying to accomplish?

                                    1 2 Previous Next