Also I want the records added to be related to the record page it was added on, so that each record in the main layout displays different portal entries relating to that record
If you enable "allow creation of records via this relationship" in the relationship that links your layout's table occurrence to the portal's, you can add new records to a portal just by typing data into the blank fields of the "add row" that now appears in your portal below the last existing record.
Not everyone likes using the Add Row. A button can be clicked that adds a record to the portal. The most commonly used script looks something like this: (Note that the user will not see the layout changes made by the script.)
Set Variable [$ID ; value: LayoutTable::PrimaryKey ]
Go to Layout ["portalTable" (PortalTable) ]
Set Field [PortalTable::ForeignKey ; $ID ]
Go to layout [original layout]
Option 2 can trip a great many script triggers and a portal's "Scroll status", among other things can change due to the layout switches. While lest often done, it's possible to use a secondary "Create" relationship to add the new portal record without actually changing layouts.
If you have this relationship:
You add another relationship using a second occurrence of the portal table:
LayoutTable::TempField = PortalTable|Create::__pkPortalTableID
"Allow creation...." would be enabled for PortalTable|Create.
Then this script can be used to create a new portal table record:
Set Field [LayoutTable::TempField ; "" ]
Set Field [PortalTable::anyField ; "any value" ]
I understand the relationship part. Option 1 sounds like enough for me, but I still am confused how to link the portal and the layout table so that it understands that they are related. I made a field in each called item ID and made the layout one equal to a serial number and the portal field equal to the item ID but that didn't work
Like any other relationship, you set it up in Manage | Database | Relationships. You find the match field in the table occurrence box of one table and drag to connect it to a table occurrence box in another. That produces:
LayoutTable::IDField = PortalTable::IDField
You then double click the relationship line to open a dialog where you can select "allow creation..." for the PortalTable (occurrence).
Note that IDField should be defined to auto-enter an ID each time you create a new record in the LayoutTable. An auto-enter serial number field is still the most often used method for this though it can also be a text field that uses an auto-enter calculation to enter the results of Get ( UUID ).
Okay awesome. My only question left is how do I auto enter serial numbers for layout records already created?
Show all records on that layout. Put the cursor into the serial number field and use Replace Field Contents from the Records menu. You'll find that there's a serial number option and you can also set it to update your "next serial value" setting at the same time.