Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Struggling with Loop script.

Featured Replies

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

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.

  • 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 by Guest

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.

  • 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 by Guest

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.

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

  • 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

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

Important Information

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.