3 Replies Latest reply on May 8, 2009 5:15 AM by mmccarty

    help with script to set field from current record in another table

    DonorTracker

      Title

      help with script to set field from current record in another table

      Post

      I have an INCOME table which I am browsing. I'm trying to create a script that will create a new record in another table, MEMBERS, using some fields from the current record I'm viewing in the INCOME table.

       

      I've created a script to do this, but I haven't figured out how to get the script to take the source fields from the current record in INCOME. It seems to use some arbitrary record in INCOME as the source.

       

      What would be the simplest script to create a new record in MEMBERS, and set field "name_last" equal to the value of "name_last" in the currently viewed record of my INCOME table?   Thanks!

       

      (I'm using FM Pro 10 Adv Mac.)

        • 1. Re: help with script to set field from current record in another table
          mmccarty
            

          If the two tables are linked: When you create a new record in Members you have to provide it with the foreign key that links it to Income.  I'm not sure how you set up your keys but lets just say that you used auto entry serial numbers.  Assume the record you are looking at in Income has key_primary_income=2.  When you create the new record in Members, set Key_foreign_income=2.  Now your two tables are linked and you don't have to use Set Field for the first and last name you can just use the original fields in the Income table.

           

          If the two tables aren't linked then you could just capture the info from the Income table using Set Variable and paste it into Members with Set Field aka:

          Go to Layout[Income]

          Find[ what ever current record]

          Set Variable[$last;Income::last_name]

          Set Variable[$first;Income::first_name]

          Go to Layout[Members]

          New Record/Request

          Set Field[last_name; $last]

          Set Field[first_name; $first]

           

          Hopefully one of these suggestions helps.  If you want to tell me a little more about how the two tables are related I mite be of more help.

          • 2. Re: help with script to set field from current record in another table
            DonorTracker
              

            I could use some help with this portion:

             

            Go to Layout[Income]

            Find[ what ever current record]

             

            If I'm already browsing Layout[Income], how would I Find the current record?

             

            Update: it looks like if I set my variables first (without using a Go to layout), while I'm in the current record, then they'll have the correct field/record values.
            • 3. Re: help with script to set field from current record in another table
              mmccarty
                 If you are going to find the Income record that you want and then run the script, don't worry about the Go to Layout or Find script steps.  I included that part incase you ran the script from another layout in your database.  Just start the script with the Set Variable script steps