4 Replies Latest reply on Mar 3, 2016 10:29 AM by steveoh

    I need my script to run only once..

    mjbenun

      This probably has a very easy solution- just not sure what that would be.

       

      I have a script that I am going to attach to a script trigger- and it will be activated on record load.

       

      However, once this script is run for a particular record I don't want to run it again.

       

      What is the best way to go about accomplishing this?

       

      Thanks!

        • 1. Re: I need my script to run only once..
          thurmes

          The way I've done this in the past is to have a field, maybe called ScriptHasBeenRun, numeric, that is set to 0 or just blank initially, and that is set to 1 when the script is run. The script, of course, checks to see whether that field is set to 1 and exits if so, like this:

          If YourTable::ScriptHasBeenRun

               Exit script

          End if

          This instruction is run early in the script, so it doesn't waste time doing things before running this check.

          • 2. Re: I need my script to run only once..
            mjbenun

            Thanks for the quick response! I will give that a try.

            • 3. Re: I need my script to run only once..
              mjbenun

              I just figured out an even better solution for my purposes.

               

              I attached the script to a button.  Since the script populates a particular field when run (among several other steps) I simply put a formula into the "hide object when" area that tests to see if this field is empty.  If it's not empty, the button disappears and no way to mistakenly run the script a 2nd time..

              • 4. Re: I need my script to run only once..
                steveoh

                mjbenun wrote:

                 

                I just figured out an even better solution for my purposes.

                 

                I attached the script to a button.  Since the script populates a particular field when run (among several other steps) I simply put a formula into the "hide object when" area that tests to see if this field is empty.  If it's not empty, the button disappears and no way to mistakenly run the script a 2nd time..

                 

                Another idea is to add a field to that record that is set to 1 when the script is run.  That way you can have it set up on record load and not require any action on your part.  Just add a script step in that script that sets the field to 1 and have the script run only if that variable is 0.

                 

                For example, lets call that number field "check", your script could look something like this:

                 

                If [Table::Check = 0]

                     (Run your script)

                     Set Field [Table::Check ; 1]

                End If