1 Reply Latest reply on Mar 31, 2010 3:05 AM by LaRetta_1

    Script to Update Field



      Script to Update Field


      I have a database I want to use for a tournament. When the tournament is over, I want to have a script that will order the list based on points and then fill in a field with their place number (the first row would be 1, the second 2, etc).  I can sort the database, but I need to know how to enter the values into the field.  Any ideas?

        • 1. Re: Script to Update Field

          Once the records are sorted, you can use either a looping Set Field[] or Replace Field Contents[].  I suggest you use a loop if your solution is multi-user because you can test for record locking properly.


          Looping method:


          Go to Layout [ layout based upon this table ] ... or only use a button on this layout to fire this script

          Show All Records

          Sort [ Restore ; No dialog ]

          Go to Record/Request/Page [ First ]


          Set Error Capture [ On ]

          Set Field [ yourTable:: Rank ; Get ( RecordNumber ) ]

          If [ Get ( LastError ]

          Set Variable [ $error ; $error & yourTable::uniqueID & "|" & Get ( RecordNumber ) & ¶

          End If

          Go To Record/Reqest/Page [ next ; exit fter last ]

          End Loop

          If [ not IsEmpty ( $error ) ]

          Show Custom Dialog [ $error ]

          End If


          If a record is locked because another User is modifying it, this displays the primary key and rank number in the custom dialog so you can manually set them when the record is free (write the information down before saying OK to the custom dialog; once the script finishes, the script variable will disappear).  You can also write to global variable so value persists until you close or you can write to a field.  Also note that Custom Dialog won't display but a few lines. Usually, there would only be one entry and it is easy to write it down at the time or you can search for blank Ranks.  But writing to multiline and saving that information provides good protection for capturing fields which won't properly set because of record locking, paraticularly with many Users or on large record sets or with complex scripts.


          You can also use Replace Field Contents[] ... however, even though you can test for locked records, this script-step will only tell you that you received a 201 (record lock) at the end so you cannot capture which record was locked.  Only use Replace Field Contents[] if no Users at the time or if you can search for unset records afterwards.


          UPDATE: Back up before running any new process.