The OnObjectEnter trigger fires after the event (see http://www.filemaker.com/12help/html/script_trigg.38.2.html#1029602). I would surmise (someone will correct me if I'm wrong) that clicking the checkbox is processed before the focus is changed to the checkbox field. Hence, the order of events probably looks something like this:
1) User clicks the checkbox.
2) Checkbox value is toggled.
3) Focus lands in field.
4) Trigger fires.
To work around it, I suggest you change the field to a button that runs a script. The script can do something like this:
Go to Field [ MyField ]
# Script trigger fires here
Set Field [ MyField ; Case ( MyField = "Retired" ; "" ; "Retired" ) ]
You got me thinking. So if the check box field (Retired) had mutilple values how would I capture these initial values.
If I took your approach of making the field (Retired) a button that would run this script:
Go to Field (Result)
Go to Field (Retired)
and then I can modified the result and the initial values are included.
As soon as you go to the field, your initial values are captured by your triggered script, are they not?
In such a case, you would do something like this:
Begin triggered script
Set Variable $$originalValue ; table::Retired
End triggered script
Set Field [ Retired ; Case ( not IsEmpty ( FilterValues ( $$originalValue ; "Retired" )) ; Substitute ( $$originalValue ; "Retired" is a carriage return.
This would add the value "Retired" to the end of the list if it's not already there, and remove it if it is, while preserving the rest of the original value.
I dropped on the OnObjectEnter trigger as it really isn't doing what I want. I don't want the value of the checkbox field to be altered when user clicked in the field. Your button work around approach is great as I just want the existing value as it was before the user clicked in the field. So having the button set the Result field to the value of the Retired field is fine. Then by placing the user in the Retired field they can alter the values if they wish.
I do not know if this is a better work around, but I created a set of steps at the end of my trigger script that copies the contents of the checkbox field to another "copy field" using SetField. So the "copy field" will always contain the current contents of the checkbox field before it is clicked. The "copy field" can then be used to compare (using PatternCount) to the checkbox field. This way the script "knows" if I am deselecting or selecting. Let me know if further explanation is needed. Hope this helps.