3 Replies Latest reply on Apr 11, 2012 9:55 AM by Oliver_Reid

    Create a related record by script


      Hi All


      I'm trying to create a related record by the following script.


      I have setup a unique ID as the Parent:PrimaryKey in the main db



      Go to Layout [OriginalParentLayout (ParentTable)]

      Set Variable [$Scan; Parent::PrimaryKey]

      Go to Layout [AnyChildLayout (ChildTable) ]

      New Record/Request

      Set Field [ChildTable::Foreignkey; $Scan]





      When it comes to setting the value in the "Set Variable" dialog what should I be entering?


      Also, if there is a better way to accomplish this other than a portal, I would appreciate the help.



      Thank you,



        • 1. Re: Create a related record by script

          Hi John,


          I think there is a confusion....


          You have 2 tables : Parent and Child.

          You have a relationship:



          If you set the $variable to the Parent::PrimaryKey then go to the ChildLayout and create a new record and set the Child::ForeignKey to the value of $variable then you have created the relationship.


          WHat I want to know is where you have used a portal at all?


          BTW: You could have done this in the ParentLayout by simply entering data for name DOB etc in a Portal for ChildTable ON THAT LAYOUT. This would require the options on the relationship to allow records to be created via this relationship.


          There are some excellent resources for you to read about relationships. Look in the Technical Resource Centre Tab.


          - Lyndsay

          • 2. Re: Create a related record by script
            Stephen Huston

            Your variable $Scan seems to be set correctly as you have written it. Is there a problem with your script? Is the new record not being created in Child?


            If it's not being created, this may be a permissions issue of the user not having permission to create Child records. Or the layout may be set to not allow editing. Of the Child's foreignKey field may not be editable or may be set to validate as unique or some other issue.


            Is the script acting on a pre-existing Child record rather than creating a new record before setting the fKey? This may indicate a loop to test for a new record with a blank fKey is needed before executing the SetField.


            You might benefit from a Commit Record step after the SetField.


            The script as you have written it looks like it should work, assuming all the other file and field settings don't conflict with what it's trying to do. Let us know what the problem is.

            • 3. Re: Create a related record by script



              Go to Layout (original layout)


              at the end of the cript will make the whole procces invisisble to the user.