Can you send a screen shot of the actual script? Are all the fields Text Fields?
I think your SetFieldIs Wrong. there are two Specify buttons on the script step. the first is for the field you are setting the second is the value you are assigning. when all said it should look like this
Set Field [ TestTbl::phone_field; $input2]
1 of 1 people found this helpful
use the set field function. When the Set Field script step is highlighted there are two buttons in the lower right hand corner. One button is used to select the field which is the target which receives the data. The other button is used to enter a calculation which generates the data.
To input a variable, simply type the variable name, e.g., $input2
To input a calculation, enter the calc, e.g., "(" & Left ( $input1 ; 3 ) & ") " & Middle ( $input1 ; 4 ; 3 ) & "-" & Right ( $input1 ; 4 )
You don't have to use a script to format a field's content on the fly; that's what an auto-enter calculation is for (Manage Database, Fields tab, Options, Auto-Enter tab). Enter your calculation and uncheck the "Do not replace …" option unchecked, so subsequent changes trigger a re-calculation.
Simply use your first calculation; you can replace the field reference with the Self keyword:
"(" & Left ( Self ; 3 ) & ") " & Middle ( Self ; 4 ; 3 ) & "-" & Right ( Self ; 4 )
Thanks to all who responded.
It was not clear that the objective was to use both buttons. It seemed it was one or the other.
This clears up several issues regarding script functions.
Thanks again to all!
Thanks! Indeed you are correct. Using "both" buttons resolves the issue and several other ones.
I have used a somewhat different solution. I have a "Phone" text field in my table, enforced as numeric only with a maximum of 10 digits.
I also have a "PhoneFormat" calculation field with the following formula:
If ( not IsEmpty ( Phone ) ; If ( Length ( Phone ) = 10 ; "(" & Left ( Phone ; 3 ) & ") " & Middle ( Phone ; 4 ; 3 ) & "-" & Right ( Phone ; 4 ) ; "Invalid Phone" ) ; "" )
This basically returns "" if there is no phone number in "Phone", or "Invalid Phone" if not exactly 10 digits, or the formatted phone number like (###) ###-####.
On my layouts, I add a field for PhoneFormat, and UNCHECK everything in the "Field Entry" section. This field is immediately on top of the Phone field, and is NOT a tab stop.
When tabbing through the form, when the focus gets to the Phone field, the user types in 10 digits, and when the field is exited the PhoneFormat field again becomes visible. This seems to work just fine.
FMP (even 13) seems to have a validation quirk. If I limit the length to 10, then enter 11 digits and tab off the field, it immediately warns me and I need to go back to the field and correct it. If instead I validate by calculation and that calculation says must be exactly 10 digits, the validation does not happen until I leave the record. This is why I used the calculation in PhoneFormat to display an error message, which it does immediately.