Check the found count in the related record first, by going related to it or by having a sum on your mother record of related records. If there are none, then just create the new mother.
Makes sense. I'm assuming I need to add and If/Else statement to each related record loop based on sum of related records (e.g. IF > 0, continue, Else Exit Loop.
Yes, exactly. Or just check before going into the loop creating the new related records.
The GoToRelated record step has its pitfalls, including that if there are no related records the step will not resolve.
In place of GoToRelated, I would recommend to simply script a find for parent record ID in both child tables. Then you simply need to put the Exit condition as the first step of each loop and you'll be good to go.
It will be easier for us to present a modified script if you present your original script as a PDF so that we can copy and modify the script steps.
Regarding GTRR, the preferred method AFAIK is first determine if related records exist:
If [ isEmpty( relatedRecord::ID)]
#no related records exist so handle this condition
Go To Related Record
Process record set
This is my preferred method, Bruce. TEST first!
Since the primary key field in the related table should have something if there is a record, testing for IsEmpty() on that field is the correct way to see if there are any related records. Some have tried Count() or other functions/tests which are NOT the correct test.
Thank you everyone for your help. I've instituted your suggestions and the script now works as required. Next time I have a question, I will provide the script in PDF form. Thanks again.
My favorite function to check related records is "IsValid(TO::primaryKey)"
But that is most definitely the wrong expression.
As has been discussed on most every FileMaker board; since forever.
Use isEmpty. Exactly as described by Bev.
I believe Bev and Bruce, but official document says use Count()
I know FMI does bonehead sometimes, but this may be not, at least "work but may not be best always".
And in help file, both IsEmpty() and IsValid() don't have any sentence about "if there is no related record", only IsEmpty() has "or if some other error occurs", but referring related field makes no error if "record is missing". So, IsEmpty() is not usable for relations not using "=".
(Of course this is not OP's case)
I found a web site talking about which to use.
If this is the reason for using IsEmpty, I think joerg is not "wrong".
If primary key has invalid value, the record is already broken. You can't get "correct result" without correcting it anyway.
Hmm, I tried to say "not usable" in case of relation table has no primary key.
In the case, Count() also not usable if there is not any other alternative field to count.
I thought once I heard IsValid(relatedTable::fieldMayBeEmpty) is usable in such case, but ? (Of course this is not usable if the field have invalid value...)
I myself don't want to use other than IsEmpty(), but why FMI documents its clearly, if it is "since forever"
Every time IsValid comes up in this context, listen closely. You are hearing the audible groans of 10,000 FileMaker developers who've been over and over this.
As Bev and Bruce said: IsEmpty is the correct function.
Sorry Bruce, but I strongly disagree … and I can prove it.
In case of equal relationships IsValid( ) and not IsEmpty( ) both return TRUE if there are related records present. But in case of an X-relation (Cartesian product) this could be different. At least if the field of the detail table used in the relationship is empty, the calculation not IsEmpty( ) returns FALSE, still there are related records available. IsValid( ) still returns TRUE in these cases.
You can download my sample file from the German forum FileMaker-Magazin where this issue is also discussed (https://filemaker-magazin.de/forum/beitrag/156542). Don't worry, I use English terms in the sample file (https://filemaker-magazin.de/attachements/156542/original/IsValid_IsEmpty.fmp12.zip).
Wrong. See message 12.