February 13, 200719 yr It turns out I am terrible with Filemaker, so I'm hoping someone can help. I have a database that will be used by several people and so I want to make it dummy proof. For each of two tables there is a layout, so I use "layout" to refer to both a new layout and table in this description: On layout #1, I have a button that, if clicked, should switch to layout #2 and 1) create a new record if the ID field in layout #1 does not exist in layout #2, or 2) go to an existing record if that ID does exist. Thus, there will never be more than one record in layout #2 for each record in #1. Hopefully this makes sense. Any help is much, much, much appreciated!
February 13, 200719 yr Assuming that the record is related, the script would be something like: If [ Is Empty (Table2::ID) ] Set Variable [ $recID; Table1::RecordID] Go to Layout [ Layout 2 ] New Record [] Set Field [ Table2::ID; $recID ] Commit Record [] Else Go to Related Record [ Show only related record; from Table: "Table2"; using layout: "Table 2" ] End If
February 15, 200719 yr Author Thanks very much! It is almost perfect but there is one scenario in which it doesn't work. Example: From record #6 at main table/layout, I click the button and it takes me to layout 2, which contains a record ID field and a portal to another table. It correctly fills in the record ID field with a 6. But if I go back to the main table/layout via another button I created WITHOUT having entered data into the portal, and then click on the button you provided the script for again, it takes me to layout 2 but creates a second record with a 6 in it. This does not happen if I enter data into the portal the first time I go to layout two. Very confusing to me. Regardless of whether or not you provide a fix for this, I very much appreciate your help! This forum is really great for users such as myself.
February 15, 200719 yr After seeing this thread again and since there will only be one record, I think that if you 'Allow Creation of Record' in your relationship from Table 1 to Table 2, then you can shorten up the script to be: If [ Is Empty (Table2::ID) ] Set Field [ Table2::ID; $recID ] Commit Record [] Else Go to Related Record [ Show only related record; from Table: "Table2"; using layout: "Table 2" ] End If Also next time that you post something, it may be better if you use actual names rather than abstract Table 1, Table 2, while the layout naems being the same. It just adds confusion for others that might read the thread.
February 15, 200719 yr Author That didn't work either. I imagine I have something set up in an amateurish way that is preventing full functionality. So I took a slightly different tact. For the button that takes me back to the main layout from the second one, I edited the script and had it check to see if a record was created in the portal. If it wasn't, it deletes the record before returning to the main layout. Seems to work. Thanks again for your help!
Create an account or sign in to comment