5 Replies Latest reply on Mar 10, 2010 8:54 AM by JoshO.

    Copying Data with a Script



      Copying Data with a Script


      I'm brand new to FM and am trying to figure out how to transfer data using a script.  I want to create a button on one table which runs a script to copy some data onto another table.  Do I use copy, paste, for this, and jump between the two layouts for each copy, paste.  I tried using the set field step but nothing seemed to happen.  I'm just having trouble figuring out how something like this would look.



        • 1. Re: Copying Data with a Script

          My first question would be, "Why are you copying data from one table to another?"  Not that you never should, but there are definitely times when it is an indication of a flawed structure and data redundancy.


          Assuming you are using v8.5 or higher (maybe 8, can't remember if 8 had variables or not).


          Starting on the record you want to copy data from:


          Set Variable [$VaribleName; TableName:FieldName]

          Go to Layout [Layout Name]

          ...find what ever record you need to copy the data to.

          Set Field [TableName::FieldName ; $VariableName]

          ...rest of the script

          You can set multiple variables if you need to.  Set all the variables, the go on with the rest of the script.  Then use multiple Set Field steps.

          • 2. Re: Copying Data with a Script

            I'm using FM 8.0v2.  It's got variables.


            It's definitely an indication of a flawed data structure, but I'm new at the organization, and I didn't make it!  Registration data from a web form must be entered into one of several databases, but there's no way to know if the registration data is not spam and what database it should go to without actually looking at it.


            I'll give what you said a shot and let you know.  Thanks for your help.

            • 3. Re: Copying Data with a Script

              I hear you.  It's always tough at first when working on a solution that someone else built.

              • 4. Re: Copying Data with a Script

                It works!  Thanks so much for your help.


                The script:


                Set Variable [ $FirstName; Value:WebForm Students::FirstName ]
                Set Variable [ $LastName; Value:WebForm Students::LastName ]
                Set Variable [ $JobTitle; Value:WebForm Students::JobTitle ]
                Set Variable [ $Organization; Value:WebForm Students::Organization ]
                Set Variable [ $AddressType; Value:WebForm Students::AddressType ]
                Set Variable [ $Street1; Value:WebForm Students::Street1 ]
                Set Variable [ $Street2; Value:WebForm Students::Street2 ]
                Set Variable [ $City; Value:WebForm Students::City ]
                Set Variable [ $State; Value:WebForm Students::State ]
                Set Variable [ $Zip; Value:WebForm Students::Zip ]
                Set Variable [ $Country; Value:WebForm Students::Country ]
                Set Variable [ $HomePhone; Value:WebForm Students::HomePhone ]
                Set Variable [ $WorkPhone; Value:WebForm Students::WorkPhone ]
                Set Variable [ $Email; Value:WebForm Students::Email ]
                Set Variable [ $StudentType; Value:WebForm Students::StudentType ]
                Go to Layout [ “Students” (Students) ]
                New Record/Request
                Set Field [ Students::student_first_name; $FirstName ]
                Set Field [ Students::student_last_name; $LastName ]
                Set Field [ Students::student_title; $JobTitle ]
                Set Field [ Students::student_organization; $Organization ]
                Set Field [ Students::home_or_work; $AddressType ]
                Set Field [ Students::address_street_1; $Street1 ]
                Set Field [ Students::address_street_2; $Street2 ]
                Set Field [ Students::address_city; $City ]
                Set Field [ Students::address_state; $State ]
                Set Field [ Students::address_zip_code; $Zip ]
                Set Field [ Students::address_country; $Country ]
                Set Field [ Students::phone_home; $HomePhone ]
                Set Field [ Students::phone_work; $WorkPhone ]
                Set Field [ Students::email; $Email ]

                • 5. Re: Copying Data with a Script

                  And just as a side note...


                  You could, if you so desired, use one variable.  Separate each value with a carriage return, and then for the Set Field step use the GetValue () function to extract the value you want.


                  It requires a little more tracking on your end...but an option.  (Not that I would use it with that many variables...but good to throw in the tool kit)