filemaker only views the FIRST related record via a relationship in what you have setup. That is why it is modifying and only works once.
What you need to do is create a new related record first, then set the values in that new record into the new record.
Usually, people write simple scripts tied to a "save" button to do that:
Set Variable [ $id ; Table1::primaryKey ]
Set Variable [ $field1 ; Table1::global1 ]
Go To Layout [ table2 ]
Set Field [ table2::foreignKey ; $id ]
Set Field [ table2::field1 ; $field1 ]
Go To Layout [ original layout ]
What am I doing wrong?
Hard to tell without seeing your script.
Thanks for the help.
Can you expand a little on your example script?
What do the two set variable commands do?
Will the Go To Layout command actually take the user to that layout? I want to stay in the popover.
The Set Variables are not needed for the Global fields but it is needed for the Primary key since it is not a global.
Mike gave you a good suggestion. If you are looking for another suggestion you could create another relationship between Contacts and Enrollment. Create a global text field in Contacts called g_uuid and a text field field in Enrollment called uuid.
Your relationship is g_uuid to uuid. Set the relation to allow creation of new records. In your save script add Set Field [g_uuid;Value: Get(UUID)] to the beginning of the script. Then use Set fields to set the relevant values into the Enrollment table. The Set Field will create the new record and you never have to leave your layout to use this technique.
Or, if you don't use UUIDs, also create an “allow creation” relationship, put a very small portal based on that relationship into the popover, give it scrollbars, 3 rows, an object name and a “Hide if” condition of 1, and script
Go to Object [ "portalName" ]
Go to Portal Row [ last ]
Set Field [ PortalTO::someField ; LayoutTO::gSomeGlobal ]
Set Field [ PortalTO::someOtherField ; LayoutTO::gSomeOtherGlobal ]
which all happens within the popover.
It works as you suggested!
I don't understand how it works....but it works.
It works because the uuid is a unique value that can only create one related record. Each time you save, it reset the uuid to another unique value. Using Set Field is an undocumented feature in FileMaker that allows you to create related records. If you don't want to create the two extra fields, the technique that Erolst described also works well. If you already have a relationship set up to allow creation of new records you wouldn't need a new relationship. Beware that if you relationship allow creation of new records, anytime you use the relationship in a portal,the user might be able to create a new record in the portal by going to the last row in the portal and entering data.
the two variables are the record ids you need to populate your "join" table ... add a script step New Window then Go to Layout.... a utility table(the join table) offscreen to create a new record [table2]. Close the Utility Window and you'll be back on the popup.
Set Variable [ $id ; Table1::primaryKey ] // ContactID
Set Variable [ $field1 ; Table1::global1 ] // CourseID
New Window [ Style: Document ; Top: (Get (WindowDesktopHeight) ; Left: Get (WindowDesktopWidth)]
Go To Layout [ table2 ] // this is a utility table / the join table for Enrollment
Set Field [ table2::foreignKey ; $id ] // foreign key in enrollment
Set Field [ table2::field1 ; $field1 ] // foreign key in enrollment
Close Window [Current Window} // dismisses the utility window
//Go To Layout [ original layout ] //don't need