2 Replies Latest reply on Jun 9, 2009 11:39 AM by philmodjunk

    Halting a script if it has already been run

    njoyce

      Title

      Halting a script if it has already been run

      Post

      How do I stop a script if it has already been run?  I have several tables with different pieces of information that all relate back to one study (e.g. changes made, people added, etc.) and I have a running list of everything that happens to each study in another table called "history". But if by accident I click the button twice to run the script that creates an entry into the history table indicating that something has been done to this study, I get duplicate records. I want the script to halt if it has already been run.

       

      thanks so much for all your help.

       

       

        • 1. Re: Halting a script if it has already been run
          kapitaen_1
            

          this could be done by a (global?) field named "hasalreadyrun". in your startup script (or somewhere else) set this field to "0". in your script you wan to be run only once first check if the field is "1". if it is "1", abort the script. if the field is "0" set it to "1" and simply continue the script.

           

          greetings from germany

          chris 

          • 2. Re: Halting a script if it has already been run
            philmodjunk
              

            If you can set up a test that checks for something in your database that tells you the script has just been run, you can put an IF step at the start of your script that exits or halts the script if that is the case. What kind of test your devise depends on your script and your database design.

             

            Here's an example from my own database:

             

            I have a housekeeping script that must be run once a day. If it is run twice, I get duplicate records in several tables. I have a table where I log the date this script was last run. I have an If step at the beginning of the script:

             

            If [LogTable:: DateLastRun = Get(CurrentDate) /* Script has already been run */]

              Exit Script[]

            End If

             

            In your case, you will need a different test. Perhaps there is a change that the script makes when you run it that you can check, perhaps you can log the date and time in a time stamp field and if the same script was run in the past 10 seconds, or ...?