What is your table structure and relationships?
If "Allow creation of records..." is enabled for this portal's relationship as it seems, why do you need a script? You can simply type data into this bottom portal row to create the new related record.
I try to avoid interacting with portals like this if at all possible. Scripts to do so are vulnerable to breaking should someone alter the layout design in the future.
Try this script instead:
Set Variable [$Key ; value: ParentTable::PrimaryKeyField ]
go to layout [layout to portal's table]
Set Field [Portaltable::ForeignKeyField ; $Key ]
go To layout [original layout]
Note: PrimaryKeyField and ForeignKeyField should be the two fields used to define the relationship used for the portal.
Thanks Phil. I'll give it a go.
The script sorta works. It does bring me to the correct layout and set the $Key value but some odd behaviours have occured. Not only does it fill in the Lesson ID but it automatically fills in other fields with incorrect or non-applicable values, which I feel it should not. Also, every time I make a new record, a record line and an extra portal line are created. The extra portal row also fills in values that should not be there. Should I not have both sides of the portal relationship be able to create new records from the relationship? Could that be it?
Furthermore, I notice that the the extra portal rows get filled in with the first record information, whatever I try. Furthermore, if I go to the related record and return, there are about three identical portal rows.
You need to describe the relationships involved here. Are there fields in the portal row that were selected from other table occurrences than the one named in Portal Setup's Show Records From drop down? If so, how are their table(s) related to the portal's table?
Are they calculation fields or fields that use "Looked up value" to refer to data in another table?
The extra bottom row is probably due to "allow creation of records via this relationship" being enabled in the relationship on which this portal is based. It is a check box you can select or clear in manage | Database | relationships when you double click the line linking these two tables. This feature adds a blank "add" row to the bottom of your existing records where you can create a new related record simply by entering data into this blank portal row.
Thanks for the response.
There are two different tables being called in the portal row. The relationships are as follows:
Seasons::Season_ID=FileUsage::Season_ID with the "allow creation of records..." clicked on the Seasons side
FileUsage::Lesson_ID=Lesson::Lesson_ID with the "allow creation of records..." clicked on the File Usage side
The portal appears on the Lesson table.
The problem is that when it creates an extra row, it automatically fills in some of the fields with info from the top row. Then when I click into other rows, it replaces any unique information with the information from the top row.
"The portal appears on the Lesson table"
Please confirm that in layout setup... you see "Lesson" in the "show records from" drop down. This would indicate that the portal is located on a layout that is based on the Lesson Table Occurrence.
Then open portal setup and tell me exactly what text you see in "show Records from" in this dialog. (This will tell me on which table occurrence the portal is based.)
In layout mode, click each field and check the name shown in "display data from" in the top of the Inspector's data tab. If the part of name to the left of the :: doesn't exactly match the name in Portal Setup's "show Records from", it might explain the behavior you are seeing.
Any time you add a field to a portal from a different table occurence (Table occurrences are the "boxes" connected by relationship lines in Manage | Database | Relationships), the relationship between the portal row's table and that other table occurrence determine what data will appear in that field.
Quick question: Which layout should I check for the "Lesson" in the "show records from" drop down? Lesson or File Usage? All three?
The layout where you have the portal. So far as I know, this is the only layout we are discussing here.
OK. I changed the portal setup's "show records from" to File Usage and it worked. Thanks!