brian.curran

Script Trigger to Mask a Time Field?

Discussion created by brian.curran on Apr 11, 2013
Latest reply on Dec 19, 2016 by philmodjunk

Hi all,

I'm using a script trigger to mask a Date field which works perfecty.

 

Date Mask

#This script converts dates entered as DDMMYY and DDMMYYYY with no delimitters and converts them into FileMaker dates

when the OnObjectValidate trigger is tripped.

Set Variable [ $FieldRef; Value:Get ( ScriptParameter ) ]

If [ not IsValid ( GetAsDate ( GetField ( $FieldRef ) ) ) ]

Set Variable [ $DateText; Value:Filter ( GetAsText ( GetField ( $FieldRef ) ) ; 9876543210 ) // Get just the numeric characters

entered. ]

If [ Let ( $L = Length ( $DateText ) ; $L = 6 or $L = 8 ) // correct number of digits entered ]

Set Field By Name [ $FieldRef; Let ( Y = Right ( $DateText ; $L - 4 ) ;

GetAsDate ( Left ( $DateText ; 2 ) & "/" & Middle ( $DateText ; 3 ; 2 ) & "/" & If ( Length ( Y ) = 2 ; 2000 ) + Y )

) ]

End If

End If

 

 

However, I'm trying to adapt the above script to use on a "Time" field but I can't get it to work. Please see below:

 

Time Mask

#This script converts times entered as hhmm with no delimiters and converts them into FileMaker times when the

OnObjectValidate trigger is tripped.

Set Variable [ $FieldRef; Value:Get ( ScriptParameter ) ]

If [ not IsValid ( GetAsTime ( GetField ( $FieldRef ) ) ) ]

Set Variable [ $TimeText; Value:Filter ( GetAsText ( GetField ( $FieldRef ) ) ; 9876543210 ) // Get just the numeric characters

entered. ]

If [ Let ( $L = Length ( $TimeText ) ; $L = 4 ) // correct number of digits entered ]

Set Field By Name [ $FieldRef; GetAsTime ( Left ( $TimeText ; 2 ) & ":" & Right ( $TimeText ; 2 ) ) ]

End If

End If

 

If I enter 0330 in the field with the Script Debugger and Data Viewer open, it skips several lines and goes straight to the last "End If" line. I can't use an 'Auto-enter Calculated value', as I'm using GoZync and things are not working correctly with that type of Mask. Any suggestions?

 

Many thanks

Brian.

Outcomes