Developer Tips
From Fmfaq
Go back to Quick Tips
Contents |
Generating Random Data
As a FileMaker developer, there are times when you may need to test your calculation or script on a range of data. In some cases you don't have the data in the file you're working on and, for some reason it seems like it's too much trouble to dig some up from another file.
Here are two calculation that will generate random dates and times
Random Dates
Let( [ multiplier = 10; num = Int( random * multiplier ) ]; Get( CurrentDate ) Case( Mod( Int( Random * 10 ); 2 ); num - (num * 2) ; num ) )
Random Times
Let( [ t = Get( CurrentTime ); h = Hour( t ); m = Minute( t ); s = Seconds( t ) ]; Time( h Int( Random * 10) ; m Int( Random * 10) ; s Int( Random * 10) ) )
Saving Clone Copies While Working
Affects FileMaker 8 and later:
There are plenty of times, while developing, where saving a copy of your work-in-progress is a prudent idea.
Typically, this involves heading into the OS, after closing the file, and making a duplicate. Wait! Why take all the extra effort? Here's handy two line script to save a copy for you! (return characters have been added for the readability of the script)
Set Variable [ $clone; Value: Get ( FileName )
Another version here requires you to have a folder named Backups in the same folder as the file you're working on. It also applies the current local timestamp so you know when it was saved. Note: It uses the option custom function below it - otherwise, integrate the custom function calculation into the script.
Set Variable [ $path; Value: Substitute ( Get ( FilePath ) ; [ Get ( FileName ) ; "Backups/" & Get( FileName ) ] ; [".fp7" ; "-" & DateTimeReverse ( "" ) & ".fp7"] ) ] Save a Copy as [ “$path” ] [ compacted copy (smaller) ]
Custom Function
DateTimeReverse( datetime )
Let( _Today = If( IsEmpty( datetime ) ; Get( CurrentTimeStamp ) ; datetime ) ; Right( Year( _Today ) ; 2 ) & Right( "00" & Month( _Today ) ; 2 ) & Right( "00" & Day( _Today ) ; 2 ) & Right( "00" & Hour( _Today ) ; 2 ) & Right( "00" & Minute( _Today ) ; 2 ) & Right( "00" & Seconds( _Today ) ; 2 ) )
Dedicated Values for Data Viewer
When working in a copy of FileMaker Advanced it's of great use to be able to reference common values which help you know the state of the file your working on. Here is a list of useful functions to add to the DataViewer.
Abs( Get( ApplicationVersion ) ) Get ( HostName ) Get( LastError ) Get( LastODBCError ) Get( AccountName ) Get( ScriptParameter ) Get( ScriptResult ) Get( LayoutName ) Get( LayoutTableName ) LayoutNames( Get( FileName ) ) Get( RecordOpenCount ) Get( RecordModificationCount ) Get( ActiveFieldName ) Get ( ActiveFieldTableName ) FieldNames( Get( FileName ); Get( LayoutName ) ) Get( ActiveLayoutObjectName ) LayoutObjectNames( Get( FileName ); Get( LayoutName ) ) "Local = " & Get ( CurrentTimeStamp ) & " | Remote = " & Get ( CurrentHostTimeStamp ) $counter
