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.

Loop Script Not Working Can't Understand Why?

Featured Replies

I use the following script, and it doesn't work, can anyone tell me why.

I want to show records in a layout List view where the date is today and no later than a week in the future in date order.

The Script

Enter Browse Mode

Sort Sort Order: StartDate Ascending Pickup Ascending Restore sort order, No Dialog

Show All Records

Goto Record/Request/Page

First

Loop

If StartDate >= Today and StartDate < Today + 7

Omit Record

End If

Goto Record/Request/Page

Next, Exit after last

End Loop

Show Omitted

Goto Layout Due Out

This is doing my head in, the programming to me looks fine, why can't Filemaker handle the script. Any suggestion would be appreciated.

Thanks

Bear in mind that scripts should produce the same result effects as though youo had performed each task in order.

If you perform your task by "hand" you'll find that the go to next record is unnecessary when the record was just omitted, because FM has removed the record from the found set and automatically advanced you to the next.

Personally, I would

Start from last

check/omit as necessary

if we didn't omit then go previous rec

exit if we are at rec 1

The Script tidied up a bit and made to work:

Enter Browse Mode

Sort Sort Order: StartDate Ascending Pickup Ascending Restore sort order, No Dialog

Show All Records

Goto Record/Request/Page First

Loop

If StartDate >= Status(CurrentDate) and Status(CurrentDate)+7 > StartDate

Omit Record

Else

Goto Record/Request/Page Next, Exit after last

End If

End Loop

Show Omitted

Goto Layout Due Out

--------------------

However, consider this as a solution:

Create a calculating text field (lets call it DATEFINDER) with the following calculation:

Case( StartDate >= Status(CurrentDate) and Status(CurrentDate)+7 > StartDate, “x”, “”)

Now create a find script:

-----

Perform find, restore find requests

Goto Layout Due Out

-----

This looks for the value “x” in the field DATEFINDER and goes to the right layout!

Hope this helps,

Rigsby

Mark and Rigsby pointed out a very common mistake of using Omit in a Loop, i.e., when you Omit a record, the next record becomes the current record! So the Go to Next Record step skips every record following an Omit. shocked.gif Rigsby's script corrects this by adding the Else statement.

I'm wondering, though, why not just script the Find to begin with?

Enter Find Mode( )

Insert Calculated Result (StartDate, DateToText (Status(CurrentDate)) & "..." & DateToText (Status(CurrentDate) + 7))

Perform Find( )

  • Author

Thanks a lot. all your methods worked, I've never used Insert Calculated result in find mode, I can think of loads of use for that, many thanks

laugh.giflaugh.giflaugh.giflaugh.gif

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.