With the development of the data file script steps in FileMaker 18, FileMaker has made it easier remove inefficiencies from your database. The script steps also help streamline workflows and enhance processes. For instance, script steps can allow users to create a change log, simply log other data and hold them outside of a FileMaker environment. Let’s dive into some of the new script steps…
New data file script steps in FileMaker 18
The lot of data file scripts includes: Close Data File, Create Data File, Get Data File Position, Get File Exists, Get File Size, Open Data File, and Write to Data File.
Example of how to use the data file script steps in FileMaker 18
The above script steps should be used in the following
order:
Get File Exists -> Create Data File / Open Data File
-> [Get Data File Position] -> Write to Data File -> Close Data File
-> Get File Exists/ Get File Size
By using the following steps, we can safely ensure that a file exists, open that file and then write to that file. If we were to use an abridged method, we may run into issues where the file does not exist or the script fails to open the file.
In the above script workspace, we can see the following…
- Standard FileMaker procedures implemented to set a file location path as a variable
- We check to see if the file exists
- If the file does not exist, we make a file using the predesignated $fileLocation
- We open the file to insert data using a loop to iterate through each instance of Blog sample::Name..
- If the file does exist, we immediately exit the script as we are not expected to overwrite data in this example
The expected outcome of the file location is within the documents folder, as set by our $filelocation variable (below).
Here’s what the outcome shows:
As you can see, it iterated through the name of people in the phone book, appends the “:” and the phone number at the end from the data below.
We can also use the File Delete script to delete data files via scripts. However, this script can return with errors if it cannot find the file (example below).
As you can see, it deleted the file.
File rename script step in FileMaker 18
Another new feature is called File Rename, which checks if the file exists, and renames it. However, this script can also return with errors if it cannot find the file. As you can see below, I’ve built it into our older script to catch for duplicates and to rename them old_FileName and to create a new data file.
And the file was renamed to Old_Phonebook5_10_2019.txt and a new file phoneBook5_10_2019.txt was created.
Maintaining data integrity in FileMaker 18
It is important to note at this time that if a file is open by another user on a shared drive, or by the person running the script, the script will run into issues. This is because of the nature of file locking and how OS’ manages simulation data connections. These issues can be resolved or avoided by simply disallowing users from accessing the raw data files by putting them in an invisible folder, disallowing access to the folder or educating the user with regards to file locking and data integrity standards.
Reach out to us!
I love hearing from members in the FileMaker community, so if
you find any other use cases, things that you’d like me to test or anything else
you find interesting, drop a note in the comment section! I’d be happy to chat.
Or, if you’re reading this and think you might be ready to
take the next step with your project, but would like some help, reach out to us
for a free consultation.