4 Replies Latest reply on Mar 28, 2017 8:59 AM by philmodjunk

    Script IF statement

    GJBDJC

      Uggg... The simple stuff drives me crazy!

       

      I have a script and within the script an IF statement, very simple:

       

      IF (global field A = "X")

           Set Field (Field 1, gField1)

           Clear (Select; gField1)

      End IF

      IF (global field A /= "X")

           Set Field (Field 2, gField2)

           Clear (Select; gField2)

      End IF

       

      Everything works EXCEPT the CLEARs???

        • 1. Re: Script IF statement
          jbrown

          Good morning.

          I would use Set Field to clear the field:

          Set the field to "" (or blank)

           

          SetField [YourField; Value: ""]

           

          the Clear function is rarely used for the reasons Bev mentions below☺. I'm not sure I've ever used that script step.

          • 2. Re: Script IF statement
            beverly

            Clear requires the field to be enterable (& on the layout). It's like copy, cut & paste. Use

            Set field ( gField1 ; "" )

             

            beverly

            • 3. Re: Script IF statement
              Kevinwcampbell@hotmail.com

              I think just replacing Clear (Select; gField2) with a Set Field with calc result "" will work and clear the field.

              • 4. Re: Script IF statement
                philmodjunk

                Clear is a step to be avoided UNLESS it's exactly what you need.

                 

                It only works if the field is present on the current layout--so this is likely why it didn't work for you, but there are other reasons why it may not have--though much less likely.

                 

                It puts the cursor (the focus) in the specified field. This change of focus can trip a number of script triggers on your layout. Not only OnObjectEnter on the field being cleared, but if the focus is on a field with a trigger such as: OnObjectExit, OnObjectValidate, they will be tripped as well. Since the focus may not be the same place each time, you can even get a "mystery bug" where something unexpected happens only part of the time as your script may be tripping one of these triggers only some of the time.

                 

                BUT: if you want that cursor to be automatically placed in the field ready for input as part of the clear, then much of the time, it makes sense to use clear. But even then, I sometimes find it better to use set field followed by go to object to put the cursor where I want it. That's in cases where the field that I'm clearing has been placed in more than one spot on the current layout--such as might be done with a global text field used for "temporary input".