Creating subrecords when none exist
Clearly a FMP newbie, but not new to databases...
Accounts --> Cases is a one-to-many relationship.
The Accounts Layout has a portal showing Cases with a descending sort by Case Number. If the current Accounts record has some subrecords (Cases), the script I wrote easily creates a new subrecord with a Case Number that is conditionally incremented (each Account has Cases that start with Case Number 1). This script is executed when browsing the current Accounts record and works fine.
I don't want the user to be able to create a new Case by just editing that Accounts Layout portal. I want a button to do this. That's why I wrote the above script. I have all fields in the portal noneditable. The Case Number on each portal line is a button that takes the user to the related subrecord where they can edit fields other than the Account Number or Case Number.
My problem is that I can't figure out how to allow the script to create a subrecord when no subrecords already exist. When they exist, I just use the GoToRelatedRecord step and go from there. But that script step doesn't seem to help me here. I don't see a way to let the script move into the Cases Table/Layout unless there's already a related record there.