Jump 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.

IsValid() returning 1 on non-existent field

Featured Replies

  • Newbies

I am writing a script that takes a parameter which is part of a field name (eg. BusDev ) and then builds the field's full name, looping until it generates a field name that doesn't exist.

Completed_BusDev_01 [ perform calculations ]

Completed_BusDev_02 [ perform calculations ]

...repeat...

Until you generate a field that doesn't exist and drop out of the loop.

I have tried to break out of the loop using IsValid (ie. Exit Loop If [ not IsValid($completed)] ) and IsEmpty (ie. Exit Loop If [ IsEmpty($completed) ] ), but neither one works. The loops continue well beyond the existing fields until I break out of the loop manually via a custom dialog option.

So, what am I doing wrong? The included FMPro help for IsValid states that IsValid returns 0/false if the references to the field or parent table are invalid.

Is there any other built-in function that checks if a field exists/is accessible ?

Completed_BusDev_01 [ perform calculations ]

Completed_BusDev_02 [ perform calculations ]

...repeat...

What does “perform calculations” mean? Within a script, a field does not stand for itself, but is the target of an action.

Try that action and check if it generates an error code which you can then handle.

There is a difference between a field's name as text and a reference to a field. If you have a variable containing text, and you want to know if a field so named exists, try =

IsValidExpression ( $fieldName )

Other than that, it's a bit strange that you need to write a script without knowing which fields you have. Not to mention that numbered fields, such as Completed_BusDev_01, Completed_BusDev_02, etc. are usually a symptom of poor structure. Most likely, you should be using multiple records in a related table instead of the multiple fields. Then it would be also very easy to loop among them, if at all necessary.

Looks like you're just asking if the variable is valid. That won't tell you anything about a field.

Try this:

Exit Loop If [ not IsValid( GetFieldName( Evaluate( $variable ) ) ) ]

  • Author
  • Newbies

[ perform calculations ] means I am performing various calculations with the created field variable and other variables.

I realize this is a sub-optimal design, but it's use is small scale for a single individual. It's use requirements changed repeatedly midstream.

The reason for the variance is that there are clusters of related fields that apply based upon a selectable field. I wanted to write a single script that could handle all cases without hard coding each cases' limits and instrad find them programmatically.

I will try your suggestion. Thank you.

Ps. Interesting. I thought the use of a locally defined variable in these functions would use them as their intended field reference and not just a string literal.

Update: Exit Loop If [not IsValidExpression($completed)] gives me the function I am looking for.

Thank you for your help.

Nice one, Michael. So many functions, so few brain cells...

Create an account or sign in to comment

Important Information

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

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.