3 Replies Latest reply on Jun 17, 2009 8:28 AM by philmodjunk

    script help



      script help


      I am stuck on figuring out how to write a script which can add (or subtract) a numbered entry in a series of a specific fields through an entire database.  My program is a tree inventory in which unique tree data is entered for a specific plant.  If a tree is removed from the property, I want to script a button which will change the tree number from a specific point in the inventory by lessening the data by one.  ie: a property has 1256 trees which were inventoried.  A month later tree 612 falls down and is not a part of the inventory anymore.  I want to have a button which eliminates tree 612 and changes the sequence through the entire data base.  I would also like to have a button which does the opposite where if a tree is planted, the opposite happens across the data base whereas adding to the numbering sequence.  Any help is much appreciated' - John

        • 1. Re: script help

          Replace field contents can do this by specifying a calculation.


          However, I wouldn't advise the approach you appear to be doing. Why not keep the serial numbers unchanged and either delete the tree record or change a status field in the tree record to "removed" or such? Then there is no need to renumber all your tree records--which can really complicate data integrity.


          If you are trying to maintain a count of how many trees exist on a given property, there are other methods for getting this count without having to renumber your records.

          • 2. Re: script help
               Thank you or your response.  From an archival perspective I think you may be right in simply identifying the fact that a tree was a this location at a given time and have the database simply document the removal date...  However, I am in the middle of a 5800 tree inventory and it is inevitable that I will miss a plant on my first pass through an area and have to reenter it after prior data has been collected.  My real question in this thread should have been how to insert a record (or numeric value to the entire database) at a given point and add one to all at the point of insertion.
            • 3. Re: script help

              What makes the sequence of these numbers important so that you must keep them in order?


              In terms of database function, this is rarely necessary. Keeping them unique is all that is really necessary in most cases.


              To answer your specific question.


              Replace field contents can be set up to use the following calculated expression in its specify calculation:


              table::NumberField + 1


              If you run this option either manually or in a script with table::NumberField as its specified target, the value in the field will be incremented by one.


              To put it all together


              Use a Find operation to find all the records where you need to increment the number

              Run Replace field contents with a specified calculation to increment them.