7 Replies Latest reply on Jan 30, 2012 1:44 PM by philmodjunk

    Trouble evaluating a field

    Kat11_1

      Title

      Trouble evaluating a field

      Post

      I am putting  together a layout where users will initially enter the information which will not change in the future although it is theoretically possible that in rare instances it could.
      I would like to build in the safety feature that would prevent unintentional changes and record the changes that end up being made. I wrote a script that on OnObjectEnter evaluates the field and if the field is not empty pops up a question Do you want to change this field? for the user when they click into a field and the field is not empty. If they proceed (say yes) the existing content of the field gets stored in a separate tracking field including time stamp of the change  and user is prompted to enter the reason for change and and the new  data. If they choose no it exists the script.
      I got the part that pops the question if the  field is not empty and prompts for the reason and new data working. I run into the problem though because the question ends up popping up just AFTER a user enters the field for the 1st time too!
      I tried to do this using on OnObject Enter and OnObject Modify with the same result. How do I get this question to not pop up when the field was empty upon entering?
      Thanks for your help!

        • 1. Re: Trouble evaluating a field
          philmodjunk

          Is this a field with an edit box format, drop down list, pop up menu, radio button, or checkbox group format?

          I'm guessing it's a pop up menu as there's a quirk or bug that let's the user select a value in the popup before the OnObjectEnter trigger will kick in and perform the script.

          You can capture the prior value of the field if you pass the value of that field as a script parameter to the script trigger. Then you can compare the current value of the field to the original to determine if the value was changed (and if the script parameter is empty, you know it's a new value). If the use cancels out of the change, you can use that same script parameter value to revert the field back to it's original value. This still results in the script kicking in after the change, but at least you can still log the change and give the user a chance to cancel out of it.

          • 2. Re: Trouble evaluating a field
            Kat11_1

            Thank you for your response Phil! It is a drop down calendar. Below is my script. I am not sure at which point would I compare the Script Parameter with the content of the field. Everything I try seems to be a non ending loop.

            If [Evaluate(file::field)  ≠ ""]
              Show Custom Dialog ["Do not Change"; " note to user…"]
                  If [Get (LastMessageChoice)=2]  // reversed 1 and 2
                    Show Custom Dialog ["Reason for Change"; "note to user …"; file::change_note_field; file::field]
                    Exit Script
              `     Else If [Get (LastMessageChoice)=1]
                    Enter Browse Mode []
                    Exit Script []
                End If
            Else If [Evaluate (file::field)  = ""]
                Exit Script
            End If

            • 3. Re: Trouble evaluating a field
              philmodjunk

              Evaluate is not the function to use here.

              Try this variation of your script:

              If [Not IsEmpty ($$OldValue ) and $$OldValue ≠ Table::Field ]
                Show Custom Dialog ["Do not Change"; " note to user…"]
                    If [Get (LastMessageChoice)=2]  // reversed 1 and 2
                      Show Custom Dialog ["Reason for Change"; "note to user …"; file::change_note_field; file::field]
                `  Else
                      #revert value
                      Set Field [YourTable::YourField ; $$Oldvalue ]
                  End If
              End If

              This requires a second script written as:

              Set Variable [$$OldValue ; get ( ScriptParameter ) ]

              Use the OnObjectEnter trigger to perform this script to capture the original value of the field in a global variable when you first enter the field.

              IF $$OldValue is empty, the original value of the field was empty and the change is accepted without any dialog appearing. If $$OldValue is not empty and it doesn't match the current value,  then a change has been made (Thus clearing the field after previously entring a data also triggers the custom dialog...)

              • 4. Re: Trouble evaluating a field
                Kat11_1

                Another elegant solution, thank you! The only thing that would not work for me is if I use it with on OnObjectEnter trigger only. If I us eit with OnObjectModify it works. Thank you!

                 

                • 5. Re: Trouble evaluating a field
                  philmodjunk

                  You need two triggers, one to capture the original value on entry and one to capture it on exit. I prefer to use OnObjectModify for fields where the user cannot enter data by typing and OnObjectSave on fields where they can. (If they can type data into the field, OnObjectModify will trip on every keystroke.) OnObjectSave trips only if the data in the field has changed so it trips a few less times than onObjectExit.

                  • 6. Re: Trouble evaluating a field
                    Kat11_1

                    Good point. On object save doesn't seem to work in this case. maybe because it is a dropdown calendar?

                    • 7. Re: Trouble evaluating a field
                      philmodjunk

                      It should work, use it all the time in my systems--even with drop down calendars. Keep in mind that onObjectSave only trips if the value changes and the custom dialog will only appear if $$oldvalue is not empty.