November 22, 200817 yr 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.
November 22, 200817 yr 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.
November 22, 200817 yr Author 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, 200817 yr by Guest
November 23, 200817 yr 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.
November 23, 200817 yr Author 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, 200817 yr by Guest
November 23, 200817 yr 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.
November 23, 200817 yr 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
November 23, 200817 yr Author 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
November 23, 200817 yr 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
Create an account or sign in to comment