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.

for each() function

Featured Replies

Hi, I am desperate to find some kind of a 'for each record' function but I can't find it anywhere.

Ha anyone an idea how to to this?

Thanks.

You might need to write a looping script. See the FM Help for Loop/End Loop. More info will get you better advice.

  • Author

Great, thanks for the answer, I had never done any scripts in FM before, was not aware of the Loop function!

I have tried it in the following but still have issues with the script.

My first table, Sales Invoices, contains all the invoices, each of them with a field Job Number (each invoice is linked to a Job, there can be several invoices per Job Number).

My second table, Job Numbers, contains all the jobs. In this table, I would like to add a field that gives the total amount invoiced per Job Number.

I have named this field Total_Invoiced and set its value to Calculation '=$$Sum', ie the result of the below script. But nothing happens....

Set Variable [$$JN; Value:GetField (Job Numbers::Job Number)]

Set Variable [$$Sum; Value:0]

Go to Layout ["Sales Invoices" (Sales Invoices)]

Go to Record/Request/Page [First]

Loop

If [sales Invoices::Job_Number = $$JN]

Set Variable [$$Sum; Value:$$Sum + Sales Invoices::Amount USD

Go to Record/Request/Page [Next; Exit after last]

Else

Go to Record/Request/Page [Next; Exit after last]

End If

End Loop

Go to Layout [original layout]

Thanks for your help!

You dont need a script for this...

Create a new calculation field in the Job Numbers table.

cTotalJob = Sum ( Sales Invoices::Amount USD )

And this post is a perfect example of why it is best to explain what you are trying to do, and let whoever responds offer the best technique.

While it's true that more information is usually better, a for each call IS explaining a lot (if one knows what for each means). Sometimes those coming from other languages don't know what to ask for except in their terminology. It can be a frustrating transition when reading FM Help and not seeing anything which even remotely fits - I know. :wink2:

  • Author

Thanks for the answers

@bcooney: the Sum() function solved all my problems, thanks a lot, no need for a script indeed. But good to know how to use the Loop function anyway.

@LaRetta: glad you understand it is not always easy to discover a new language!

Z.

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.