8 Replies Latest reply on Jan 23, 2017 9:26 AM by meyerge

    Script to clear a form

    meyerge

      Hi Everyone,

       

      I am a bit stumped on this one. I have created a customer search form/ list. Once it have found the record I am looking for I would like to copy the fields from the form and paste them into a new record in an order entry form. How can I clear the contents of the search form using a script, after a search so I can perform another search? I was thinking of attaching the script to a button.

       

      I am using FM15.0.2.220 on OSX 10.12.2

       

      Thank you in advance for taking the time to consider my question.

       

      Gordon

        • 1. Re: Script to clear a form
          keywords

          From what you describe, I would suggest you do NOT use cut and paste, but rather create a script that does the following:

          1.     Starting on the form you have found, use Set Variable to gather up the data you want to to carry over to the new record. You can use a single Set Variable step to create multiple variables or a series of steps to create one variable each—either way will work as long as the variables themselves are named appropriately ($xxx).

          2.     Go to the layout where the new record is to be created, create the new record and then populate each relevant field with the appropriate variable.

          3.     Go back to your starting record and use a series of Set Field steps to blank each field ready for next time. (note: you could perform this step before step 2 if you want to.)

          • 2. Re: Script to clear a form
            siplus

            the set variable method is great if everything is in the same file. Otherwise you should build a parameter list and pass it to a script in the other file, which will decode the parameter list, create a new record and populate fields accordingly to the parameters.

            • 3. Re: Script to clear a form
              meyerge

              Thanks for the feedback. In this particular case everything is contained in the same file. Since I am new to the programming side of FileMaker the insight from you more experience developers is greatly appreciated. I haven't heard of the "parameter list" concept before so I will definitely learn about it.

               

              Thank you again.

               

               

               

              Gordon

              403.585.9489

              • 4. Re: Script to clear a form
                keywords

                I imagine what siplus means by a parameter list is like this—

                The most commonly used variable is what is often called a local or script variable, because it is created within a script, remains current as long as that script is running, and is then cleared as soon as that script is closed. These variable are named with a leading $—e.g. $thisVariable.

                Because they are local to the script in which they are created, if you want to call another script within that script you have to pass the variable(s) over to the called script. This is usually accomplished by way of a script parameter when the called script is activated.

                To set a parameter list you can use a calculation in the initial Set Variable step, along the following lines. In the Set Variable dialog, call the variable $dataToGather or some such, and make its content a calc such as the following:

                Let (

                [

                    $firstVariable = <first field name here>

                  ; $secondVariable = <second field name here>

                  ; $thirdVariable = <third field name here>

                  ; $etc = <another field name here> // as many more fields as there are values you want to gather up

                 

                  ; list = List ( $firstVariable ; $secondVariable ; $thirdVariable ; $etc )

                ] ;

                list

                )

                Because the variables within the first part of the Let expression are themselves named with $ signs, they will individually be declared both within this expression and as local/script variables, and because the list of them all is the outcome of the Set Variable expression, the list will be contained within the $dataToGather variable. Thus, in a Perform Script step you can use $dataToGather as a Script Parameter for that step, and thus pass the full list of variable across to the new script.

                • 5. Re: Script to clear a form
                  meyerge

                  A few points of clarification if you would indulge me.

                   

                  Firstly, should the "Let" actually be "Set"?

                   

                  Secondly, is the "$" at the beginning of the variable name a requirement or a convention?

                   

                  For this solution I envisioned two databases, since we have a sales force in Canada and one in the US. Unfortunately when they set up the accounting they set up a completely different part number convention for the US. The fields in the all the tables will be the same so the script would also apply in the second database, correct? Since the table names will be the same. I guess as a point of discussion, twitch the type of flexibility inherent in using variable, why would you need a parameter list?

                   

                  I did a bit of reading in the FM15 Training Series: Advanced on script parameters and realize i have a long way to go.

                   

                  Thanks for the dialog!

                   

                   

                  Sent from my iPad

                  • 6. Re: Script to clear a form
                    BruceRobertson

                    You seem to be completely on the wrong track.

                    You say you are searching customers.

                    If your search was successful, then the customer already exists.

                    If your database is set up properly, then this existing customer has a customerID.

                    So you would do something like this:

                    Set Variable [ $customerID; Customers::customerID ]

                    Go to layout [ Orders Data Entry ]

                    New Record

                    Set Field [ Orders::customerID; $customerID ]

                    Now this new order is linked (related) to the existing Customer record and data from the customer record can be displayed in the Order without any need to copy anything.

                     

                    But of course, we're missing a lot of detail, and it will in any case be an important skill for you to be able to understand and successfully set up and run scripts as described by some of the other suggestions.

                     

                    Let? Yes.

                    $? Yes. That is required to create a script variable.

                    You should probably take a look at the Invoices example template that came with your copy of FileMaker.

                    • 7. Re: Script to clear a form
                      keywords

                      Firstly, should the "Let" actually be "Set"?

                      No. Let ( ) is a calculation function which I have used here, and which I strongly recommend you learn how to use.

                      Secondly, is the "$" at the beginning of the variable name a requirement or a convention?

                      It is a requirement for declaring a local/script variable. A variable declared in the first part of a Let ( ) expression does not require the $ prefix, but without it the variable is only available within the expression itself. By using the $ prefix within the expression and then declaring the variable as the outcome of the expression it becomes available outside of that Let ( ) function for other use within the script.

                      The fields in the all the tables will be the same so the script would also apply in the second database, correct?

                      With any necessary adaptation to its new context, yes the script could be used in other files.

                      I guess as a point of discussion, twitch the type of flexibility inherent in using variable, why would you need a parameter list?

                      As explained already, the parameter list is needed if you wish to pass variable data from one script to another.

                      • 8. Re: Script to clear a form
                        meyerge

                        Hey everyone thanks for the insight. I realized after reading brucerobertson reply that I only need to set the variable for the customerID field because of the relationship that was set up between order entry and customer tables. They are linked via the customerID primary key so when the ID is placed in the OrderEntry customer ID foreign key field the remaining fields are populated.

                         

                        That being said I am looking forward to using variables in the remaining development.

                         

                        Thanks again!

                         

                        Gordon