Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Struggling with Loop script.


This topic is 5772 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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.

Picture_4.jpg

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Guest
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Guest
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This topic is 5772 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.