Let me explain. I have an abstracted record deletion script. By that I mean I want it to be able to go to any layout and find a name field an use it to find a record for deletion. This means it can be used to delete records on layouts with different tables. It goes like this;
Go to Layout( "SomeLayout" )
Go to Object( "PrimaryID" )
Enter Find Mode
Set Field ( $PrimaryID )
If found count is 1
This script fails if the found count is 0 to start with. It's not a problem if you do a Show All Records first but it is a gotcha for new players.
The problem is that when the object is a field it seems that as far as FileMaker is concerned the object does not exist unless there is a record. You can have other objects on the layout with a 0 found count and the Go to Object() function will work for them.
So my question is "Is it a bug or a feature?"
This is interesting behavior that you've highlighted.
I went ahead and created a few scripts to test the behavior myself.
A couple things to consider:
1. Field objects are children of records. In order to interact with them, there must be a record present. Whereas other layout objects, are children of layouts.
Just like you cannot go to a related record if one doesn't exist, you cannot go to a field if a record doesn't exist. Does that make sense?
Using the Go to Field will result in the same error when no records are present. (See attached screenshots below.)
2. Regarding the script steps that you've included in your delete script, why are you including Go to Object in the first place? Is there a particular reason?
3. Be wary of universal delete scripts. Each table should have it's own set of rules regarding what records can and cannot be deleted.
Go to Field Script:
Go to Object Script:
Try entering find mode before using Go To Object. That way, there's already a request with a field for you to go to. Also, you should consider entering Find Mode before going to the other layout as a performance improvement; you won't load any records over the network when you switch layouts that way.