8 Replies Latest reply on Oct 19, 2014 8:26 AM by lijnbach

    Refresh Object after script trigger "OnKeyStroke"

    lijnbach

      Title

      Refresh Object after script trigger "OnKeyStroke"

      Post

      Hello everybody,

      I have a button and a field on my LayOut. Both (as well the button as the field) changes when I am in "edit mode". (Get (RecordOpenState) = 1). The value in the field changes, and the button is hidden when in "edit mode". I use the function "Get (RecordOpenState)".

      I have a script trigger on the LayOut. It is "OnKeystroke". The script is doing the following:

      Refresh Object [ObjectName : Button]

      Refresh Object [ObjectName : field]

      The strange thing is, the field is updated directly after one keystroke, the button is only updated after the second keystroke. It seems the "refresh object" is working different on a button.

      If I use "refresh window", both are only updated after the second keystroke.

      I think I am overviewing something, but I can't figure out what. (Using FMP 13 Advanced).

      Thanks in advance,

      Hans Lijnbach

        • 1. Re: Refresh Object after script trigger "OnKeyStroke"
          philmodjunk

          Field names are not object names. Did you select the field and button objects while in layout mode and use the Inspector's name box to give them object names? Also make sure that the object name entered in the script step is exactly the same (no typos) as that specified in the inspector.

          • 2. Re: Refresh Object after script trigger "OnKeyStroke"
            lijnbach

            Hai Phil,

            Thanks again for your time.

            Yes, both, as well the field as the button have an "object name". For test purposes I kept it easy; Button1 and Field1. I checked on typos several times, because I know typos give no result on the script. I also did a second test with the same result. The field is updated directly after the first keystroke, the button after the second keystroke.

            When using "refresh window", both are updated after the second key stroke, not after the first one. (I prefer not using "refresh window", because of possible performance issues. The strange thing is, if i use a "Set Variable" in the script and use the variable to hide the button and change the value of the field,  instead of Get (OpenRecordState), it all works fine.

            Could it be a bug?

            Hans

            • 3. Re: Refresh Object after script trigger "OnKeyStroke"
              philmodjunk

              I really can't follow the details here of exactly what you are doing. There's just a few too many missing pieces. I don't follow why you are using OnLayoutKeystroke at all nor why such updates need to take place one keystroke at a time...

              • 4. Re: Refresh Object after script trigger "OnKeyStroke"
                lijnbach

                Hai Phil,

                Thanks for your patience. The reason why I am using it, is because if a user changes a field (no matter which field), one field has to be updated, and two buttons needs to be hidden. As I wrote I found an excellent work around, I was just curious why the function Get(OpenRecordState) seems to have a delay of one key stroke.

                And, because I am still learning I was wondering if I make a thinking mistake, or that it is really a bug. At this moment I use a variable based on Get (OpenRecordState) - for updating the buttons - and that works just fine. But, if I use the function Get (OpenRecordState) directly, there is a delay of one keystroke.

                Hans Lijnbach

                • 5. Re: Refresh Object after script trigger "OnKeyStroke"
                  philmodjunk

                  Yes, but I'd like to see the actual script that you are using here in order to better be able to understand and replicate what you are doing.

                  • 6. Re: Refresh Object after script trigger "OnKeyStroke"
                    lijnbach

                    Hai Phil,

                    Thanks again. Here is the Drop Box Link with a test file. (I made it in English). (I did not send you the original, because it is in Dutch)

                    https://www.dropbox.com/s/x45ch186equg11m/Refresh%20Object%20test.fmp12?dl=0

                    If there is a keystroke on the lay out, you can see that de button above (hide on Get (OpenRecordState) disappears after the second keystroke. The other button (hide on $$Button) disappears directly after the first keystroke.

                    Hans

                    • 7. Re: Refresh Object after script trigger "OnKeyStroke"
                      philmodjunk

                      All you really needed do was post the script from that translated copy of the file....

                      Without actually testing anything, I must note that there may be a misunderstanding here.

                      a) You can change the record open state without pressing a key

                      b) Pressing a key does not automatically open the record for editing.

                      What opens your record for editing is the act of putting the cursor into the field, so if you click a field, it opens for editing, but your script trigger is not tripped. If the cursor is not located in a field, you can press a key and the record's open state will not change.

                      So then I ran your scripts with the debugger and data viewer windows open so that I can watch values change. As I suspected, If I just press a key without putting the cursor into a field, the second button disappears even though the record has not been opened for editing. This then cannot be reversed by committing the record since the record is not open to be committed.

                      But then I can confirm that the upper button does not update when the record's edit state changes by putting the cursor into the field and pressing a key to trip the trigger. This is an issue worth reporting over in report an issue to see if the TS folks consider it to be a bug.

                      • 8. Re: Refresh Object after script trigger "OnKeyStroke"
                        lijnbach

                        Thanks Phil for taking the time to have a look at this issue.

                        This helps a lot to get a better view on how the record state value changes. As I mentioned, I have a good work around. But I was struggling with the fact that I couldn't get the button hidden if the record state changes. And sometimes I make a thinking mistake, and I was not sure if I was making a mistake or the software doesn't work properly with this function.

                        And I must say, I like this function because I can hide or show buttons based of what the user is doing. So it would be nice if it works properly. At the other hand, my work around works fine.

                        But I will report it to the TS people.

                        Thanks again for your everlasting patience and time,

                        Hans Lijnbach