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.

Looping assistance..

Featured Replies

Hi there,

Edit:

The basic question is:

In FMP7, Can I create a loop that will go through and process on fields in the same table with names that are identical except for a succeeding number? (For example the fields are : Value1, Value2, Value3, etc)

--------

Lots more details follow in case the above isn't clear as to what I'm trying to do.

I'm hoping this is easy enough to do.

FMP 7 -

Basically, I have a selection of related records listed in a portal.

I'm trying to create a script to copy the values from a single field in those related records to individual fields.

I know I can make it work like this:

----

Set Field[Table1::Count;1]

If [Table1::Count <= Table1::RecordTotal]

Go to Portal Row [select; No dialog; Table1::Count]

Copy [select;Table2::PortaledField]

Paste [select;Table1::Copiedfield1]

Else

Insert Text[select; Table1::Copiedfield1; "No related data"]

End If

----

But there's over 100 iterations and it seems to me that this is screaming to be looped.

My problem is, I can't figure out how to reference a field name as anything but an absoulute reference to tablename::fieldname in a script.

I'm hoping that I can somehow pass

'Textstring'+Count as a field name?

Something like

----

Set Field[Table1::Count;1]

Loop

If [Table1::Count <= Table1::RecordTotal]

Go to Portal Row [select; No dialog; Table1::Count]

Copy [select;Table2::PortaledField]

Paste [select;Table1::GetAsText("Copiedfield"+Table1:Count)]

Else

Insert Text[select; Table1::GetAsText("Copiedfield"+Table1:Count); "No related data"]

End If

Exit Loop If [Table1::Count>150]

End Loop

----

Okay I realize I'm severely butchering the syntax.. but the basic question is this:

Can I create a loop that will go through and process on fields in the same table with names that are identical except for a succeeding number? (For example the fields are : Value1, Value2, Value3, etc)

Put the fields on a layout, then use the Go to Field [next, exit after last] script step to move through them.

OTOH, lots of fields with a similar purpose usually means a relational design is required.

In the vein of Vaughan's comment, I would use GetField( ) to set the current field with a related value.

Something like

Commit Records/Requests [No dialog]

Loop

Go to Next Field

Set Field [ , GetField( "relationship" & Get(ActiveFieldName) )]

Exit Loop If [Get(ActiveFieldName) = "{last field in the layout's tab order}"

End Loop

Don't specify the field to set, only the calculation to set it. If you need an iteration number, set a global number to 1 before the Loop portion, increment it after the Set Field (i.e. Set Field [gnum, gnum + 1]), and add it to the GetField( ) function.

  • Author

Thank you both, I think I've got a handle on it now, I'm off to see if I can implement it!

Micah

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.