OnObjectEnter is triggered, but only after the field is modified. I'd use OnObjectModify for this field and pass the original value of the field to the script by putting the field's reference into the trigger's optional parameter box.
You can also set up a validation field option that rejects changes to the field via a calculation that references the lock field, but this lets the user change field field and then makes them revert it. However, it's a change at the data level rather than the layout level so it can be useful to add as a "back up" to the layout level script triggers.
(BTW am using FM11 adv)
I must be doing something wrong, the validation thing isn't working. I did make a slight change to the script and have it set to both on enter and on modify, and that seems to work.
If(not Is Empty (Get (LayoutTableName::signature)
Revert Record/Request[No dialog]
Commit Record/Request[No dialog]
Your calculated validation rule would be:
IsEmpty ( LockfieldReferenceHere )
Haven't tried this with a check box formatted field but see no reason why it wouldn't work.
I just tried that and if I remove the script trigger lock I now get an error message that says the field is only allowed to contain certain values and won't let the user out of the field unless they revert.
Exactly what a validation rule would do. It does not prevent the attempt to change the field. It catches the error after the fact and makes the user revert. That's why I use layout design means to prevent this, but leave the validation just in case I make a mistake and a user finds a way around my layout design based barriers to changing the field.
There is another way in FileMaker 13. You can stack two copies of the field on top of each other. Set each with opposing "hide object when" expressions. Use field behavior to deny browse mode access to one of the two fields. Then setting the "lock" field hides the unlocked copy and reveals the locked copy.
Great. Now I really want 13.