Newbies jedupree Posted July 12, 2010 Newbies Posted July 12, 2010 I have a need to increment a field when I select the button. This field will not always be selected but when it is, I want to find last value and increment by 1, move new value into last value field and move new value into selected field. How do I do this?
Vaughan Posted July 12, 2010 Posted July 12, 2010 Take a look at this recent post on the subject: http://fmforums.com/forum/showtopic.php?tid/215534/post/360214/
comment Posted July 12, 2010 Posted July 12, 2010 Set Field [ YourField ; YourField + 1 ] will increment your field by 1, whether it's selected or not. I don't see the point of moving the old value to another field, since the previous value is obviously the current value - 1. I am not sure why you need this: very often, such schemes suffer from not keeping track and can cause a serious problem when the user makes a mistake.
Newbies jedupree Posted July 12, 2010 Author Newbies Posted July 12, 2010 I solved by adding global field. The intent is that sometimes we generate a po number and sometimes we don't. Script checks field to see if empty or null before generating number and moving into po field. Thanks for suggestions.
comment Posted July 12, 2010 Posted July 12, 2010 I am not sure how global field solves the issue (I guess you're not accounting for globals being restored to initial values at the beginning of each session in a multi-user solution). Why not simply use an auto-entered serial number? Or, if you must have contiguous numbering, see: http://fmforums.com/forum/showpost.php?post/172165/
Vaughan Posted July 12, 2010 Posted July 12, 2010 Any process needs to allow for the possibility of record locking when updating the serial number. The best option is to create a single record table just for this serial number (like a prefs table). Script the process for getting the next number: the script needs to open the record; check for locking; if locked wait; if unlocked remember the current number and increment to the next number; close the record. It's important to assume that at one time there will be record locking and script for it. Its also important for the process to open the record, increment the number and close the record again quickly so other users won't wait for long. If the record cannot be opened the script pauses for a second then tries again. It's a good idea to put in a limit to the number of tries. This script traps for errors and returns the serial number as the script result. If there is an error of some sort it returns null, this will need to be accounted for in the other scripting that expects the next serial number. Usually the best bet to handle this is to get the number before doing anything else, and if the number cannot be generated then post and alert and stop the process. Script = Increment Number Go to Layout [ PO Number] Set Variable [ $maxtries = 15 ] Set Variable [ $count = 0 ] Set Error Capture [ On ] Loop Open Record Exit loop if [ get( lasterror ) = 0 or $count > $maxtries ] Pause [ 1 second ] Set Variable [ $count = $count + 1 ] End Loop Set Error Capture [ Off ] If [ $count <= $maxtries ] Set variable [ $current = number ] Set Field [ number = number + 1 ] Commit Record [ no dialog ] Go to layout [ original ] Exit Script [ result = $current ] Else Go to layout [ original ] Exit Script [ Result = "" ] End If
comment Posted July 12, 2010 Posted July 12, 2010 The best option is to create a single record table just for this serial number IMHO, the best option (assuming you need consecutive numbers) is a multi-record table, as described in the link above.
Newbies jedupree Posted September 8, 2010 Author Newbies Posted September 8, 2010 Sorry for the length in replying, but other matters took precedence. The script increment number works like a charm but I get error when trying to move the value back to the record that was live when button clicked to increment. Debugging the script show the increment and update to the counter record occurring correctly but then the error occurs when referencing the original record. In another db I programmed in, this was because the original record had been moved out of the buffer as the counter record was read in and incremented. Do I have to re-read the original record in order to update with incremented value and if so, example of code would be super. Many thanks for ideas on this.
Vaughan Posted September 9, 2010 Posted September 9, 2010 Any process needs to allow for the possibility of record locking when updating the serial number.
Recommended Posts
This topic is 5248 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now