The first step is to link the tables in a relationship in Manage | Database | Relationships.
In the starter solution, you have:
Projects::PROJECT ID MATCH FIELD = Tasks::PROJECT ID MATCH FIELD
If you use Manage | Database | Fields to find and open field options for Tasks::PROJECT ID MATCH FIELD, you'll find that it has this auto-enter calculation:
That will enter the value of this global variable each time a new tasks record is created.
What your "short script" does is set this variable to the value of Projects::PROJECT ID MATCH FIELD from the current record on your Projects layout.
This is not the only way to create and link child records to a parent record. Often, a portal to the child table (tasks) is used for that purpose. If "allow creation of records via this relationship" is enabled for Tasks in this relationship, you can create new records in a Portal to Tasks on a Projects layout by entering data into the bottom blank "add row" that this options puts in the portal. This does method does not require scripting nor does it require the auto-enter calculation. Many of the starter solutions use both methods with a portal on the desktop layouts and the script/global variable method used on the iPhone layouts.
Just curious if you have a link to a walk through or tutorial of the first method you discussed. I am familiar with the second and have done that but I need to do the first for a cleaner interface.
Nearly all the details are in my last post, but here they are arranged in stepwise fashion.
Open Manage | Database | Fields
Double click your child table's match field such as PROJECT ID MATCH FIELD in Tasks to open Field Options.
On the auto-enter tab, select the calculation option and enter the name of a global variable such as $$CURRENT_PROJECT_ID. Before you click OK to close the Specify Calculation dialog box, copy the name of this variable to the clip board.
Now click OK to leave Manage | Database and go to your Parent layout (Projects).
Enter layout mode and select Layout Setup from the Layout's menu.
Click the Script Triggers Tab
Select the OnRecordLoad Trigger
In the Specify Script Dialog, click the button with the + to create a new script.
Enter this script:
Set Variable [$$CURRENT_PROJECT_ID ; value: Projects::PROJECT ID MATCH FIELD ]
Paste the variable name from the clipboard as a way to make sure that you don't accidentally use a different variable name.
Click OK until all Dialog boxes are closed and enter browse mode.
Note the value in Projects::PROJECT ID MATCH FIELD
Go to the layout for Tasks and create a new record and note that the same value appears in Tasks::PROJECT ID MATCH FIELD
The key limitation to watch out for is that this requires that you always go to the child table layout (tasks) form the Parent table layout (Projects) in order to make sure that the correct value is loaded into the global variable. If a user opens the data base and goes directly to Tasks and creates a new record, the new record will have an empty match field as the global variable was never set to a value first.