Bikur Cholim בקור חולים

Tuesday, February 2, 2016

Scripting: How to clear Data from all your Fields

How to remove Data from Groups of Fields
Find out how to create a new FileMaker Pro database by making a copy of an existing database without carrying forward all the old data.

By By Chris Moyer, The Moyer Group CEO and FileMaker Advisor technical editor, and Bob Bowers, Soliant Consulting CEO and FileMaker Advisor contributing editor
First, if you're looking for a scripting solution to clear out the data in a large set of fields, you'll want a solution that doesn't require you to explicitly reference each field to be cleared out. The best way to do this is to use the Go to Next Field step to simply walk through all the fields on a layout, clearing them as you go.
Say you want to clear out FieldA, FieldB, and FieldC. Create a new Standard form layout and add just these fields to the layout. (You can also simply add all the fields, then remove the ones you don't need; that may be easier than selecting the ones you want.) Be sure not to alter or otherwise mess with the tab order on the layout. You can then use this script to cycle through and clear the fields:
Go to Next Field
Set Field [gTemp , Get (ActiveFieldName)]
Loop
• Clear [Select]
• Go to Next Field
• Exit Loop If [Get (ActiveFieldName) = gTemp]
End Loop
This script works fine in earlier versions of FileMaker. Just use Status (CurrentFieldName) in place of Get (ActiveFieldName).
Regardless of how many fields you have on the layout, this script simply jumps from field to field until it has completed a cycle of all the fields in the tab order. It "knows" when it's arrived back to the top because you store the first field's name in a global field at the top of the script. Note there's no field name specified for the Clear step -- it simply operates on the currently active field.
The script above clears data from a single record. If you want to clear the data from your entire database, you could find all records and loop through them one-by-one, or you could use the Replace script step instead of Clear. Whatever method you use, you want to be sure you're the only user in the database when the script actually runs because record-locking conflicts can cause the script to halt or prevent data from being cleared.

There's another way you can approach this problem. Make a clone of the database, thus clearing out all your previous year's data. Then import just the employee names (and any other pertinent data) from the old file. The scripting solution is the way to go when you can't easily get physical access to the files to make a clone, but if that doesn't seem to be an issue for you, cloning and importing should be a fast and easy solution.

No comments:

Post a Comment