1 Reply Latest reply on Apr 29, 2012 8:04 AM by try67

    Clearing Global Variables

    loesch

      Before I start, I will say that I'm a Java_Virgin.  I had a form that had a number that I wanted to increment.  Found the following script in another discussion and decided to give it a try.

       

      if (global.count == null) //checks to see if count exists
      {
      global.count = 1000000 //sets initial count, you can change to suite your needs
      global.setPersistent("count",true) //makes the counter a global object so it is persistent data
      }
      else
      global.count++ //increments the the counter by one when the document is opened
      var f = this.getField("jobCount") //creates a variable for the form field where the counter will be displayed
      f.value = global.count //sets the form field to equal the counter

       

      I originally placed it under Advanced->Document Processing->Document Javascripts, but it didn't seem to work (nothing happened).  I then decided to try Advanced->Document Processing->Set Document Actions and used the same code for "Document will Print".  It worked.  Each time I printed, the field would increment, print, then the displayed field would increment.  Then the problem came up.  I forgot to change the initial count from "1000000", so I changed it, but the global field stayed the same and wouldn't change.  The number need to use comes from a set of Maryland State forms and the starting number changes with each batch of 100, so I need to periodically change the starting number.  Couldn't figure how to do it, so I changed the name of the variable "count" in the script to something else and it now works.

       

      How do I clear this variable so that the initial number from the script takes effect?  I don't mind hand clearing this variable as I only need to do this once every few months.