AnsweredAssumed Answered

Script creates record in wrong table

Question asked by sneff228 on Feb 16, 2012
Latest reply on Mar 6, 2012 by LyndsayHowarth

Script creates new record in wrong table

 

I have a database set up with multiple related tables for parents to rate their youth's strengths. Parents have many youth, so I have a relationship set up where one parent has many youth. Each youth will have a set of strengths ratings. The strengths are then broken up into 9 categories, each with their own table (i.e. communication). The Youth table and the communication table are joined by the strengths table, where the relationship between the youth and the strengths is matched by the youth key, and allow creations of records is checked under the strengths table only; and the relationship between the strengths and communications table is matched by the youth key and allow creation of records is checked only under the communication table. I also have a main family table, because at some point I will add multiple parents to the same family. The family table joins the parent and youth tables.

 

My problem is this: I have a script set up for the parent to choose the youth they want to rate, then find an existing communication record that matches that youth, or create a new record if one does not already exist.

 

As it stands, my script will find an existing record, but does not properly create a new communication record in the event that one does not already exist. Instead, it creates a new record in the youth table, but with a new youth key. Strange right? It gets stranger, if I go back to that same layout and click on the script button again, it creates a related record in the communication table. Why does this not work the first time I click on the script button? Here is my scrip, and the scripts within the script. Please advise.

 

Go to Main Strengths Record (this script looks for an existing related record or creates a new record)

Perform Script [ “Set Youth ID in Strengths” ]
If [ communication::kfYouth = MainFamily::kfYouth ]

Go to Related Record [ From table: “communication”; Using layout: “Comm. Identify” (communication) ] [ Show only related records ]

Else
Perform Script [ “Create New Communication Strengths Record” ]

End If

--------------

Set Youth ID in Strengths (this script defines which youth the parent has chosen from a radio button field)

Set Field [ MainFamily::youthID; MainFamily::allyouthnames ]

Set Field [ MainFamily::kfYouth; MainFamily::youthID ]

Set Field [ MainStrengths::kfYouth; MainFamily::youthID ]

-------------

Create New Communication Strengths Record (this script should create a new record in the communication table)

Set Variable [ $UID; Value:MainFamily::kfYouth ] Go to Layout [ “Comm. Identify” (communication) ] New Record/Request
Commit Records/Requests

[ No dialog ]
Set Field [ communication::kfYouth; $UID ]

Set Field [ communication::kfYouth; MainFamily::kfYouth ]

Outcomes