nycL45 Posted November 22, 2008 Posted November 22, 2008 We have a timesheet input file that sorts chronologically (ascending) and we want a record number for each record (from 1 to 25 records) starting with the first record, automatically entered in +1 increments and ending with the last record. I have created the script below to do this but it does not work. Suggestions welcomed. Thanks. L.
bcooney Posted November 22, 2008 Posted November 22, 2008 You could just use the Replace function. However, here's the proper Loop in pseudo-code. Sort Go to Record First set variable $counter = 1 Loop Set field Invoice Record No; $counter set variable $counter = $counter +1 Go to Record Next exit after last End Loop What are you doing, though? You wouldn't set timesheet record IDs this way. You would create an auto-entered serial in the Timesheet table that assigns a unique non-meaningful id to each record. If you're just looking for line numbers on a report, you could use the @@ symbol. *this code requires FM8.5 (variables), otherwise use a global field for the counter.
nycL45 Posted November 22, 2008 Author Posted November 22, 2008 (edited) Thanks bcooney. Your code is for 8.5? I am 7. What am I doing? Looking for a shortcut to the spice islands or it might seem that way to you. : (Kidding.) The number is an entry number for internal purposes. I will try replacing your $counter variables with a global field for FM7. Thanks L. Edited November 22, 2008 by Guest
bcooney Posted November 23, 2008 Posted November 23, 2008 Yes, FM7 doesn't have variables, so you'd use a field with storage option set to global. Just hoping that the recordID that is used in relationships, the key, is not being set thru this routine. BTW, I strongly recommend an upgrade. FM7 has lots of issues.
nycL45 Posted November 23, 2008 Author Posted November 23, 2008 (edited) I am not doing too well translating 8.5 to 7. Would you translate this line: set variable $counter = $counter +1. I tried using Set field [invoice timecard::record_no.; serialincrement (1;1)] plus others and it is ng. No to this: Just hoping that the recordID that is used in relationships, the key, is not being set thru this routine. And, I will upgrade. Would like to now but it will have to wait. Edit: this script returns 2 in all the records instead of a numerical progression starting with 1. Edited November 23, 2008 by Guest
Raybaudi Posted November 23, 2008 Posted November 23, 2008 Sort Go to Record [ First ] Set field [ gCounter ; 1 ] Loop Set field [ Invoice Record No; gCounter ] Set field [ gCounter ; gCounter + 1 ] Go to Record [ Next; exit after last ] End Loop where gCounter is a global field.
Søren Dyhr Posted November 23, 2008 Posted November 23, 2008 Would you translate this line: set variable $counter = $counter +1. I tried using Set field [invoice timecard::record_no.; serialincrement (1;1)] plus others and it is ng. Not necessarily, in recursive scripting would this very likely be stored in the scriptparameter, instead! --sd
nycL45 Posted November 23, 2008 Author Posted November 23, 2008 Daniele, that worked! The struggle is over . . . and I learned a lot. Soren, not being a coding/scripting person, I do not understand what "recursive scripting" and "scriptparameter" are. Is there a glossary to check out? My thanks to bcooney, Daniele and Soren for your help. Relieved, Leonard
Søren Dyhr Posted November 23, 2008 Posted November 23, 2008 Recursive scripts are scripts calling themselves, which is an alternative to looping. A quick stab at showing how Barbaras script would be like as recursive: If [ IsEmpty ( Get ( ScriptParameter ) ) ] Go to Record/Request/Page [ First ] Perform Script [ “MyScript”; Parameter: 1 ] Else If [ Get ( RecordNumber ) = Get ( FoundCount ) ] Set Field [ Untitled::InvoiceNumber; Get ( ScriptParameter ) ] Exit Script [ ] Else Set Field [ Untitled::InvoiceNumber; Get ( ScriptParameter ) ] Go to Record/Request/Page [ Next ] Perform Script [ “MyScript”; Parameter: Get ( ScriptParameter )+1 ] End If ...where both the script and the called script is script is called "MyScript" --sd
Recommended Posts
This topic is 5845 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