4 Replies Latest reply on Aug 12, 2009 10:19 AM by KBGF75

    script steps to create new record

    KBGF75

      Title

      script steps to create new record

      Post

      I need help with design of a script to create a new record in another table.

       

      My FMP9 file includes a table of Contacts and a table of Donations.  Donation records are related to the donor‘s Contact record by contactID fields (a Donation record’s contactID_fk will always match the Contact record’s contactID_pk).  A portal in a Contacts layout shows selected fields of related Donations records.

       

      When a new Donations record is created, its contactID_fk field is filled by auto-enter as a calculated value: contactID_fk = Contacts::contactID_pk. This works ok when the new record is created while the user is in the Contacts table: my procedure is just to start entering data in a blank row of the portal.

       

      I would prefer a different procedure. I want to initiate a new Donations record by pressing a button on a Contacts layout. The script step New Record/Request seems an obvious starting point, but first I think I must go to the Donations table.  How to fill the new record’s contactID_fk field probably is trivial, but it has me stumped. Conceptually, I think I should first copy the contactID_pk field of the Contact record, then initiate the new Donations record, then paste the copied value into the new contactID_fk field. What script steps will do this?

                      -Al

        • 1. Re: script steps to create new record
          mrvodka
            

          Set Variable [ $contactID ; contactID_pk ]

          Go to Layout [ Donations ]

          New Record / Request

          Set Field [ contactID_fk; $contactID ]

          Go to Layout [ Original ]

           

          • 2. Re: script steps to create new record
            KBGF75
              

            mr_vodka proposed these script steps:

            Set Variable [ $contactID ; contactID_pk ]

            Go to Layout [ Donations ]

            New Record / Request

            Set Field [ contactID_fk; $contactID ]

            Go to Layout [ Original ]

             

            Omitting the final proposed step (Go to Layout) but trying to follow instructions otherwise, I then created a script with these steps:

            Set Variable [$contactID; Value:”contactID_pk”]

            Go to Layout [“Donation Data Entry” (Donations)]

            New Record/Request

            Set Field [Donations::ContactID_fk; $contactID]

             

            My script does not get the desired results. It creates a new Donations record and takes me to that record, which is good, but the ContactID_fk field does not get set. In the Set Field step, I specified the target field (ContactID_fk) and specified a calculated result ($contactID)

                 -Al

             

             

             

            • 3. Re: script steps to create new record
              philmodjunk
                 Note the quote marks in your set variable script step. Edit the value expression to be: Contacts::contactID_pk , no quotes. If your contacts table has a different name use that in place of "contacts" in the above example.
              • 4. Re: script steps to create new record
                KBGF75
                  

                Removing the quotes worked. Thanks.

                 

                It did present a new obstacle, which I'll make the subject of a separate post: the new Donation record is added to any existing set of previously found Donation records. I'd prefer to see a set of all Donation records related only to the "current" donor. I could resolve that with a Perform Find step, but I'm stumbling over the setting of a variable to be used in the Perform Find. More in a separate post.

                     -Al