2 Replies Latest reply on Jun 17, 2014 3:05 PM by crichter

    Create record in related table



      Create record in related table



           I want to create  a new record in a related table only if the related record is not yet existing. I also want to "copy" the KnownPeptides::NP# field content of the current record to the newly created record.

           The script below I creates always new blank records in the related table even if there is a related record.

           Any help is highly appreciated.

           Thank you,




           Set Variable [ $ParentID[KnownPeptides::NP#]; Value:KnownPeptides::NP# ]
           If [ GetField ( KnownPeptides::NP# ) = $ParentID ]
              Go to Related Record [ Show only related records; From table: “Transgenes”; Using layout: “Transgenes” (Transgenes) ]
           Else If [ GetField ( KnownPeptides::NP# ) ≠ $ParentID ]
              Go to Layout [ “Transgenes” (Transgenes) ]
              New Record/Request
              Set Field [ Transgenes::NP#; $ParentID ]
           End If





        • 1. Re: Create record in related table

               Get Field is the wrong function to use here and that's why the Go to related records step is never executed and it always creates a new related record.

               Assuming that your relationship is:

               KnownPeptides::NP# = Transgenes::NP#

               That If expression should be:

               If [ Not IsEmpty ( Transgenes::NP# ) ]

               And you just need Else, not Else If as the second part of this If Block.

               And I don't see any reason to use a repeating variable for the ParentID like you do. Given the way that you use that notation, I don't see how $ParentID [1] which is what $ParentID references mean ever get a value since you are assigning that value to $ParentID[KnownPeptides::NP#] which is not the same thing.

               But if you enabled "allow creation of records in this table via this relationship", your entire script could be reduced to a single line:

               Set Field [ Transgenes::NP#; KnownPeptides::NP# ]

               If the related record exists, the NP# field in the related record already has this value. If no related record exists, one is created. All in one script step.

          • 2. Re: Create record in related table

                 Thank you!

                 using the one line of script (set field etc.) worked perfectly.