Script that only runs once
Is it possible to make a script run only once on the first time a fp7 is opened? Not using a button
I dont remember if its under database preferences/properties or what on fmp7 but there is a place to specify a script to run on the opening of the file.
I'm now correcting an error in this example that was pointed out in a follow on thread:
There should be a Not operator in that If step:
It's found in File Options. With this option, the script will run once every time the file is opened.
If you want this script to only run a single time, ever. That can also be done by setting up the script to check the contents of a field to see if the script was run previously.
If [ Not UtilityTable::AlreadyRun ] //put your script steps here
Set Field [ UtilityTable::AlreadyRun ; True ]End If
I can see cases where you might want to set something like this up for a solution that you are distributing to multiple clients. The script could set a time bomb for demo copies in place or it could start up a "customize your solution" process that you want to only run the first time the file opens.
This option runs the script every time the file is opened, I need it to only run on the very first time?
Using Phil's logic the script will run each time but do nothing the next time it runs.
I'm looking for it to run only 1 time ever.
Do I need to set up a new field for this script or use any existing field?
What field is the step 'If [UtilityTable::AlreadyRun]' referring to?
make a new table called utility
add a field called already run
and create one record but dont put anything in the field
add the logic Phil outlined to your script
Since the script does absolutely nothing that is visible to the user after the initial opening of the file, that is exactly what you get here. The only way you can observe anything that's happening after the first time the file is opened, would be to enable the script debugger in FileMaker advanced before opening the file.
Will the script have to go to a layout based on 'Utility' table before the 'If [ UtilityTable::AlreadyRun ]' step?
Not necessarily, it depends on what layout you want as the default layout when the file opens. UtilityTable can be related in any or all layouts in your file via the X operator so that it doesn't matter which layout you are on nor which record is current.
You can also use script steps like this:
Freeze windowGo To Layout [Utilitytable]If 
End IF Go To layout [original layout]
The freeze window step will keep the layout change to and from the utilitytable layout from being visible to the user.
It doesn't seem to be working, does there need to be anything after 'If [ UtilityTable::AlreadyRun ' like = True ir false?
Not if it's a field of type number. A non zero value in the field will evaluate as True. 0 or no value will evaluate as False.
I'm going to start a new thread to add in a picture of my script, still doesn't work at the moment.
You can also just edit your post at the beginning of this thread.
Retrieving data ...