- 25.11.2022
- 165 Views
Most programs have an interface element that allows you to return to the previous screen. The widespread use of the web has greatly strengthened the use of the "back button". It may be a bit bold, but it can be said that the back button is an essential part of a good user experience (UX). Who would want to go back to the homepage and climb the stairs again to return to the previous screen, or want to restart the program? For example, you did a search in the company list and went to the details of a record. After you finish your work, you may want to return or you may accidentally go to another screen. In this case, the back button, just one click away, will be exactly the solution you are looking for to speed up your work.
In this article, we share how to make a back button with Claris FileMaker. The back button we recommend here is a practical technique that is compatible with Claris Pro, FileMaker Pro, FileMaker Go, and WebDirect, and allows you to go back to the previous screen (layout). It is essentially possible to do this with an automatically triggered script (using the On Layout Exit action with a script trigger) and a button to go back. Please note that this back button does not provide for switching between records or reloading your search results.
Triggered Script: NAV_LogLayout
The goal is to store the visited layouts in a global variable. A global variable or global field should be preferred because both are specific to the current user's session and do not affect other users. You can watch the details of global fields and global variables in our mini-training video on this subject.
The script is quite simple:
If [ $$trigger_off ≠ 1]
Set Variable [$$lay.prev; Value: List ( Get (LayoutName); $$lay.prev)]
Else
Set Variable [$$trigger_off; Value: “”]
End If
Our script is quite simple; its primary task is to add the name of the current layout to the $$lay.prev variable using the Set Variable command. Additionally, we block its operation in certain conditions with the $$trigger_off variable. For example, if a script in your application navigates to other screens to perform operations, you may not want to log these transitions in the $$lay.prev variable. In this case, if you set the $$trigger_off variable to "1" in the relevant script, it will prevent the script from running once.
The script, which we have named NAV_LogLayout, should automatically run when the OnLayoutExit condition is met in layouts that we want to record or, in other words, return to with the "back" feature. To do this, while in layout mode, select Layout Setup from the Layout menu and set up automatic triggering by selecting your script in the Script Triggers tab for the "OnLayoutExit" event.
Our first step is complete. From now on, the layout names of the layouts where the NAV_LogLayout script is triggered will be listed in the $$lay.prev global variable, with the name of the last layout visited at the top. You can see the values in the variable with the Data Viewer.
Script of Back: NAV_Back
Set Variable [$$trigger_off; Value: 1]
Set Variable [$currentLayout; Value: Get(LayoutName)]
Loop
Set Variable [$layoutName; Value: GetValue ($$lay.prev;1)]
Set Variable [$$lay.prev; Value: MiddleValues ($$lay.prev;2;25)]
Exit Loop If [$layoutName ≠ $currentLayout or IsEmpty($layoutName)]
End Loop
Go to Layout [$layoutName; Animation:None]
Set Variable [$$trigger_off; Value: “”]
We will use this script by defining it as an action for a button in layouts that require a reverse process. The script's task is quite simple: to run the Go to Layout command to go to the layout in the first position in the $$lay.prev variable. But we must also take care of a few details to avoid potential problems.
First of all, at the beginning of the script, we set the $$trigger_off variable to 1, which prevents the trigger script from operating while we go back from the current layout. If we do not do this, the back button will work properly when first used, but subsequent clicks on the second and other back buttons will only go back and forth between the last two screens (layouts).
Our second control is to check if the value in $$lay.prev is the current layout somehow. In this case, the user will assume that the back button is not working. Therefore, we set up a loop that will run until it encounters a layout name other than the top layout name.
This loop works as follows: whenever we give the back command, that is, when we click the back button on the layout we are in to go back to the desired layout, we take the name of the layout we are in to a local variable ($currentLayout), and then enter the loop. In the loop, we take the first value in our global variable to a local variable again. This is the name of the layout we want to go to. If the layout we are in ($currentLayout) is not the same as the layout we want to go to ($layoutName), we have reached the name of the layout we want to go to.
Another detail within the loop is updating the $$lay.prev variable. To do this, we update the layout list in the $$lay.prev variable starting from the two values with the MiddleValues function.
After exiting the loop, we can switch to the previous design (layout) with the Go to Layout step.
In this way, you can easily switch to the previous layout by adding a button and trigger to the layouts where you want to perform the "back" operation, without the need to search.

Download link sent to your email address