A few things stand out:
1. The Go to Layout step to take you back to your opening "receipts" layout is disabled, so you will only be on that layout at that point in the script if you have encountered a 401 error.
2. The main Loop is not closed—unless that part of the script is not printed here.
3. You have no initial Find in the script, so how do you know what set of records you are working with?
4. You potentially perform Finds in this same "receipts" layout at two other points in the script, so if your Go to next record step is intended to move you through the receipts records you cannot be sure that will be happening as intended.
That's enough for starters.
You are not looking at page two of the PDF where the loop closes. There are
two finds I made in the script. The first is to locate the PRINTS record
to update, the second is to relocate the record I was working on in
For Starters, I start at the first record of Receipts. When I GO TO NEXT I
should already be in the Receipts layout if I found the record (error
code=0) or if the record was not found (error code=401).
Soooo, I am still sorting it out..
Conceptually, I think the script has to do this:
Go to Layout (Receipts)
# you are now on your original found set of records
Go to record/request/page (First)
Set Variable ( $receiptId ; Receipt Primary Key)
Go To Layout (Prints)
Enter Find Mode
Set Field ( Receipt Foreign Key ; $receiptId
If (Get(LastError) = 0 )
Go to Layout ( Receipts)
# at this point you have switched context, but are still "on the record" you began with before doing the search in Prints layout
Go to record/request/page (Next ; Exit After Last)
# at this point you are on the "next" record in Prints layout (your original found set) and have not yet done your search in the Prints layout with information on this record
Your second Find, to relocate the record you started on, will locate only that record—presumably a found set of one. Thus Go to Next Record will fail, because there is no next record.
If you want to loop through a set of records, you might consider employing a new window for all the "do stuff" part of your script, then going back to the original window when you are ready to move to the next record. This would look something like the following:
Find whatever set you want to process
Go to First Record
Do all the other stuff
Close the second window
Go to Next Record (NOTE: you will now be back in your original window with your original Found Set and record location unchanged, so this step will now make sense) – exit after last
Do whatever other stuff you need to finish the process
Thanks for taking the time to understand and reiterate my logic. I actually eliminated the 2 "Finds" (on Receipts) in the script. So I've got it looping.
Now, my biggest problem is when I switch from all numeric (999) to alphanumeric (A999) Image Types. This is the reason I decided to do a script in the first place. When I related the Receipts to the Prints and tried to include data from prints in my layout for Receipts, Most of the match data for the Prints was missing. The data is related on fields Image and print number.
Although if I do a manual find on the layout "Expose Prints" using the same data as I am using in the script, I DO FIND these
records. And some of them actually do FIND. Bizarre.
Can anyone tell me why Filemaker will find a match for something like "401" but not "A401h"?
Where I say "and some of them actually do find", I meant to indicate that they find the records via the relationship.
That is because FM searches for individual words commencing with the specified criteria. A401h does not commence with 401, hence is ignored. If you want to search for a string within a word you have to add wildcards (*): searching for *401* will find both.
Thank you, Thank You, everyone! I found that by putting asterisks around the whole variables that are like "A101h", by setting the variable = "*"&$$Image&"*", I was able to find these suckers. That part was amazing, because I have searched and search for help with this issue!
I am looping, finding, and updating. Must be time to quit while I'm ahead!