Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 4561 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies
Posted

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 ?

Posted

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.

Posted

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.

Posted

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 ) ) ) ]

  • Newbies
Posted

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

Posted

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

This topic is 4561 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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