Thank you for your post.
Get (RecordOpenState) is intended for script usage, and the value will update a button after a refresh is issued. This is as designed.
Setting a variable is correct, but as PhilModJunk pointed out, using OnLayoutKeystroke does not guarantee this will edit a record. Instead, consider using OnObjectEnter script triggers. Entering the field will then hide the button, even though RecordOpenState is 0. Once a change is made to a field, then RecordOpenState will change to 2 (or 1 for new records).
Thanks for your reply,
No matter the discussion I had with PhilModJunk, the problem is, also after "a refresh" the button does not update. PhilModJunk has tested this also. This was the original problem. It is no disaster because I use a variable as workaround. But, if I have a button with "hide if Get (RecordOpenState) = 2", the button does not hide when editing a record. Also not after a refresh button. (It does hide, but only after a second keystroke).
The reason I did not use the "OnObjectEnter" trigger, is because I then have to that for every field I am using. I only use the "OnLayOutKeystroke" to refresh the button.
Keep in mind that an OnLayoutKeystroke script trigger is fired when the keystroke has been pressed; not the result of the keystroke. The result of the keystroke occurs after the script has been completed. Therefore, the result of Get(RecordOpenState) will be 0 at the time the script is triggered, and then 2 when the script completes. Therefore, setting the variable within the script is the correct method.
To handle the issue if the keyboard is pressed before entering a field, you may want to change the script to:
If [ Length ( Get ( ActiveFieldName ) ) > 0 ]
Set Variable [ $$Button ; Value: 2 ]
If you change the Set Variable step to Value: Get (RecordOpenState), this will set $$Button to 0, and when the script completes, RecordOpenState will return 2.
O.K. Thanks for the explanation,
I expected the result of the keystroke before the script started. But the result comes after the script. So, that explains why the "hide if Get (RecordOpenState) = 2" reacts after the second keystroke, and "hide if $$Button = 2" reacts immediately.
The way I am handling it now, with the variable works just fine. And I like this function because it is an indicator what the user is doing, and it gives a opportunity to show or hide fields or buttons, depending on what the user is doing.
Sorry if I made mistakes in my English, but my native language is Dutch.