1 Reply Latest reply on Feb 18, 2013 1:52 PM by philmodjunk

    Creating a record via script and ensuring referential integrity

    PecCars

      Title

      Creating a record via script and ensuring referential integrity

      Post

            

           Consider the tables Contacts and Requests. One contact can have many requests, thus Contact::ID = Request::ContactID as a relationship allowing creation of records in both tables via this relationship.

           In the current setup I have currently a portal where I can enter both Contact::(fields) as well as Request::(fields). A new record is created in Request provided I have created a new Contact automatically. Works fine.

           I am redesigning the application so that the user gets a list of  all requests in the dialog for contacts. The user can either click on an existing request of the list and it jumps to a window with a modal dialog for Request::(several fields) and works fine.

           I have also a button for the creation of new requests for an existing contact. Clicking the button in the Contact dialog triggers a script that is supposed to create a new Request:: record. The script does the following:

             
      •           

                       Go To Related Record (from table: „Request“ using layout „“W_ProcessRequest“); New Window)

             
      •      
      •           

                       New Record Request

             

           Apparently the relationship between both tables is not active, because although the new record is created in Request, the associated Request::ContactID is not created automatically. What do I need to do in order to create a new related record in Request while at the same time ensuring referential integrity (the relationship is there already) ?

            

        • 1. Re: Creating a record via script and ensuring referential integrity
          philmodjunk

               I strongly recommend against using Go to Related Record in this script. It will fail if this is the first Request record to create for the given contact and you can end up with a new record created in the contacts table instead of Requests.

               Use this script instead:

               Freeze Window
               Set Variable [$ContactID ; value: Contacts::contactID]
               New WIndow...
               Go to Layout ["W-ProcessRequest" (Request)]
               New Record/Request
               Set Field [Request::ContactID ; $ContactID]