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.

Script step for related records

Featured Replies

I need to find a way to look for related records or skip the step if none exist. What I really need is: If Status(CurrentRelatedRecordCount)=0

Go to Record (Next) exit after last... or something like that.

Is there a way around this without performing a find in the related file?

try:

if (is empty(relationship::relatedrecordID))

go to record request next

else

do something else

end if

  • Author

Sounds good.

I will let you know.

Thanks

I had this problem in a script I never found out why it wasn't working.

But I now use the is valid(your relationship) function and it works like a charm.

Alternatively, use:

If ["Count(TheRelationship::ForeignKey) = 0"]

This is closest to your original request, as it works off a count of related records.

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

Michael

Yes, Like daltwin, I routinely use the formulation:

not Count(Relationship::Key)

to test for an absence of related records.

There are various other methods, including IsEmpty and IsValid, both of which will work for most cases - but each of which can produce unexpected results under certain conditions.

IsValid in particular can produce some unexpected results if it targets any field other than the key field, since it is actually testing for more than just the presence of a record (eg a field may return as invalid even though the related record exists, depending on the data in it - and conversely, a null field will return as valid, though this may not alwways be what is expected or desired...).

IsValid in particular can produce some unexpected results if it targets any field other than the key field, since it is actually testing for more than just the presence of a record

Thank you for pointing out. I'm really surprised and would like to understand exactly whay you mean.

I use this for almost all my scripts "create a record if none exists"...I'm kind of...scared now that you pointed this.

With all these solutions leading to the "quite same result, is it that there are different use according to the type of relationships ??? one to one, one to many, many to many ?

Thank you.

Hi Ugo,

I didn't mean to alarm you. ooo.gif If you are working with text keys and text targets for IsValid, then there should be no problem - though if you are not targetting the key field with your IsValid( ) formula, then you need to bear in mind that you are testing for the presence of the record, rather than for a value in the field - whereas the reverse is true for IsEmpty( ). wink.gif

It is primarily where you may be working with other field types (eg date or time) that IsValid can produce a negative result for more than one reason, and the risk becomes greater if it is not targetting the key field for the relationship it is testing.

If the field type is text and you are targetting the key field, then there is no reason for concern. However when suggesting a method on the forum I figure that the safest and/or most universally applicable is best. Especially when it is not clear exactly how the idea will be applied by the recipient or others. cool.gif

I am not quite sure I agree. The initial request was to

look for related records or skip the step if none exist.

Is it more accurate to count the related records and see if they are above 0, or to look for the presence of any relationship? It would seem to me that in theory, the count and evaluate involves 2 steps, while the is empty(foriegn key) involves one and is closer to the original request (not looking for how many, but the presence of).

I realize that this is splitting hairs, and do appreciate the potential flaws in the IsValid method, but I cannot think of any scenario where the IsEmpty(ForiegnKey) will return a different result than Count(ForiegnKey)=0.

I use IsEmpty for all such calcs (it is just slightly easier to program for me), and would be very interested to learn if I have been failing to consider something.

And again, IMHO IsEmpty seems conceptually closer to the desired request.

-Raz

Hi Raz,

We aren't in disagreement - my only reservation about IsEmpty( ) relates to cases I have seen where it has been used on a field other than the foreign key - and that can lead to problems, as you'd appreciate.

In fact, Count( ) must also be used on the Foreign Key in order to reliably test the relationship so, as you say, they are close to functional equivalence.

If efficiency were at issue, there may be an argument for using If ["Count(Relationship::ForeignKey)"] as a positive test (ie to confirm that there are related records) and If ["IsEmpty(Relationship::ForeignKey)"] as the negative equivalent. They are certainly both compact. smile.gif

Thanks Ray,

I spent so much time learning FM in a vacuum (before I discovered this board) that I am not always sure IsValid(MyConvictions) returns true (much better than IsEmpty(MyConvictions)) grin.gif. Nice to know I dont have to worry about going back and updating all my calcs of this nature.

-Raz

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.