Jump to content

I need a button to conditionally switch layouts


This topic is 5702 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This topic is 5702 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.