That message should not pop up 4 times. Other than the validation error message, is the record save confirmation dialog the only other message that appears?
Do you have auto-save turned off for this layout? Do you want that?
Does your script have commit records steps in it?
You could set an OnObjectValidate trigger on the field and then create your own script to validate data in the field.
Auto-save is turned off for this layout. I want to control when the record gets saved and think I am doing that in the attached script. It seems to work as planned except for the time field.
In looking at the data it appears that if just a 1 is entered into the time field the system sees that as a time of 01:00:00 and my script step test passes and the script continues with all of the commit record steps which must be prompting the save confirmation. I just don't know how to fix it.
Yes. Entering 1 into a time field will be interpreted as entering a time of 1 am. FileMaker will not interpret that as an invalid time with the settings you have given.
But it's very easy to commit records from a layout even when it has been set to disable the auto-save. Just clicking the layout back ground will commit records and cause the "do you want to save?" dialog to appear.
What seems very unusual is to get this dialog 4 times. As far as I can tell, this will not come from the script you've posted as it commits with the "no dialog" option specified.
Try this test:
Enter an invalid time and click the layout background. This should both pop up a validation error message and try to commit records. Do you get the same results as when you click your button to save the record?
I think that you will need an additional script performed from an OnObjectValidate trigger set on your time field in order to get the results that you want. That script can validate the data in your time field before the validation field options set on the field can kick in. An Exist Script [False] step can then cancel out the field exit and return the focus and the user to the time field to correct invalid entries. (And if you don't want to except simple numbers from 1 to 24 as time input, your script can detect and react to those data entry issues as well.)
I have set one large invisible (Do Nothing) Button on the layout behind all the input fields to prevent committing the record so I can do it with the script. So when I enter something invalid like an A in the time field nothing happens unless I click in another field and then I get the invalid time message.
I'm updating this as I test. So I just made a copy of the layout and deleted the big do nothing button. When I enter an invalid time I get the error and an option to revert when I click on the background. And as I mentioned earlier if I run the script it goes crazy. I'll try your suggestion of adding an OnObjectValidate trigger and write another script to validate the input and we'll see what happens.
OK, so once again I'm lost. I have decided to make the SessionTime a text field, I don't care about AM & PM and do not need to do any time calc with this field. Now I can test in the main script for a few things. First I check to see that the length is either 4 or 5. If it is 4 I want to be sure there is a colon : in the second position and if the length is 5 their should be a : in the third position. Any help will be greatly appreciated.
That sounds like checks that you could build into your existing "Save" script. If it proves a valid entry, part of the save could be to then enter this data into an actual time field:
Set FIeld [ YourTable::TimeFIeld ; GetAstime ( YOurTable::TextTimeField ) ]
I didn't think of that…I'm testing the global field and it makes sense to then enter it into a time field. What I need help with now is determining if it is in the correct format. How do I test to see if there is a : in the third position from the right. I've tried the Right function and PatternCount but can't figure this out.
Use the Position function to check for both the presence of and the position of the colon.
Thanks again Phil…it is now working as planned. I learn something new every day