11 Replies Latest reply on Jan 26, 2011 10:29 AM by ebthatsme

    User Input to local variables then scripting to perform a find.

    ebthatsme

      Title

      User Input to local variables then scripting to perform a find.

      Post

      In my database, I want to allow the user to input 2 pieces of data that I want to use as the values for local variables within the script and then use that input to perform a find. I can do it with global variables but I'd rather use local variables if possible. Is it possible? If so, how do I code that?

      Attached is what I'm using as a script with the globals.

      Thanks

      post.png

        • 1. Re: User Input to local variables then scripting to perform a find.
          philmodjunk

          Variables or fields?

          Your script example uses global fields, not variables.

          If you want to use local fields you have to move the data into variables before you enter find mode as find mode will render any data entered in a local field inaccessible until you return to browse mode.

          Set Variable [$gr ; value: measurementRegistration::GrLev]
          Set Variable [$meas ; value: measurementRegistration::meas]
          Enter Find Mode []
          Set Field [MeasurementRegistration::GRLev ; $gr]
          Set FIeld [MeasurementRegistration::AsmtCode::$meas]

          I'm using fields in the one table you identify in the script above as the source of values for the search criteria. You can, of course, modify this example to load values from whatever local fields you want to use as the source of your search criteria.

          PS. Set field does not require that the cursor be in the field in order to work. In fact, the field doesn't even have to be present on the layout as long as the layout refers to the table where it is defined. Thus, you can remove the go to field steps in your original script and you'll still get the same results.

          • 2. Re: User Input to local variables then scripting to perform a find.
            ebthatsme

            Currently, both ... but what I want is to use local variables that derive their value from user input.

            The info being requested from the user does reference information from local fields ... but I want the user to supply me with the specific values of those fields and conduct the search based on that. What I'm confusing is how to combine getting user input with creating local variables in the script so I can perform the find.

            When I tried it with globals ... then I did use global fields in the table to hold the requested search criteria from the user. But, what I'd rather do is simply get the user to give me the two pieces of information (grade level of students and specific measurement records) then assign those two user given values to two local script variables and perform the search. 

            Does this make any more sense?

            • 3. Re: User Input to local variables then scripting to perform a find.
              ebthatsme

              Basically, 

              What I want is this:

              I want to start a find ... ask the user to give me what grade level and what measurement they are interested in, take that information and put it into two local variables within the script that will then go perform a find based on those two requested bits of data ... and return all the records that match those two criteria - i.e. grade 7 NWEA measurements.

              That's the English language version of what I want. Does this help?

              • 4. Re: User Input to local variables then scripting to perform a find.
                philmodjunk

                Not really. The script example I gave uses two local variables. (or do you mean local fields?)

                How do you want to "ask the user"? In a special search layout or tab? In a dialog that pops up? or ?

                The basic script is the same, the only difference is in what fields you will enter the user's input before starting your script.

                I really don't see any advantage over this from your original scirpt. Global fields work very well for this purpose.

                • 5. Re: User Input to local variables then scripting to perform a find.
                  ebthatsme

                  Try this explanation ... 

                  Using what you wrote above ... in red is what I need to understand.

                  Set Variable [$gr ; value: measurementRegistration::GrLev  comes from user input]
                  Set Variable [$meas ; value: measurementRegistration::meascomes from user input]
                  Enter Find Mode []
                  Set Field [MeasurementRegistration::GRLev ; $gr]
                  Set FIeld [MeasurementRegistration::AsmtCode::$meas]

                  I don't know how to tell the value of the local variable to be dependent on user input.

                  Does this explain it better?

                  • 6. Re: User Input to local variables then scripting to perform a find.
                    ebthatsme

                    Okay - maybe I asked the wrong kind of question ...

                    You said,

                    How do you want to "ask the user"? In a special search layout or tab? In a dialog that pops up? or ?

                    Maybe that's my problem, I'm not sure of the best way to get user input if what I want to do is use local variables within a script. I realize that global fields will do what I'm asking ... that's how I'm currently handling it. I've just heard that global fields are not always the best option ... and that often local variables are a better choice b/c they dump the data when the script is done. So, I was trying to look for a way to avoid the global fields and go for local variables.

                    • 7. Re: User Input to local variables then scripting to perform a find.
                      ryan

                      i'm curious: 

                      do you really even need variables?

                      Might you be able to you use the "Show Custom Dialog" Script step, then use the two fields MeasurementRegistration::GRLev & MeasurementRegistration::AsmtCode as Input fields?

                      • 8. Re: User Input to local variables then scripting to perform a find.
                        philmodjunk

                        You can't, you have to use one method or another to allow the user to enter the values into fields such as the global fields that you are already using.

                        Here's an example, with global fields. If you want to use local fields you can adapt it with the variables as I have already described above, but I see no purpose to doing so:

                        Show Custom Dialog ["Please enter some values" ]
                        # In the previous step, Specify two input fields to link to MeasurementRegistration::g_gr and MeasurementRegistration::g_meas]
                        Enter Find Mode[]
                        Set Field [MeasurementRegistration::GRLev ; MeasurementRegistration::g_gr]
                        Set FIeld [MeasurementRegistration::AsmtCode ; MeasurementRegistration::g_meas]

                        Note: Show Custom Dialog is only one of three different ways to do this. It's easy to set up, but you can't format the input fields with value lists and you can't validate the input until after the user dismisses the custom dialog so it may not be flexible enough to work. The other approaches, however, still use this same basic script.

                        • 9. Re: User Input to local variables then scripting to perform a find.
                          ebthatsme

                          Thank you ... I needed to hear, "You can't" ... now I can move on to messing with which "you can" method works best for our needs. I appreciate your ideas and direction. Talking through issues helps me and I appreciate your time.

                          • 10. Re: User Input to local variables then scripting to perform a find.
                            philmodjunk

                            If you want to examine a method that uses the New Window command to pop up a more sophisticated window than you can get with show custom dialog, download a copy of my Known Bugs List and see how the find button (and its scripts) work. (Careful, there's a loop that will trap you with no way out but to force quit FileMaker unless you have buttons or scripts set up to use Halt script to exit the loop.)

                            • 11. Re: User Input to local variables then scripting to perform a find.
                              ebthatsme

                              Thank you ... will check it out!