Jump to content
Sign in to follow this  
devices99

Get(LastError)=401 vs Get(FoundCount)=0

Recommended Posts

Get(LastError)=401 vs Get(FoundCount)=0

Is there any advantage/disadvantage to using either of these, when scripting and checking if a find returns no matching records? (Obviously I always test for the last error immediately after the find.)

Could either ever be tripped up and give a wrong result?

I've been using FM since the early days and have always tested against error 401, but in recent months I've started to convert a system and in new scipts I've been erring towards get(foundcount), perhaps for readability...

(This particular system I'm working on is v11, and will be upgraded to v12 next year.)

Share this post


Link to post
Share on other sites

AFAIK they are equivalent for testing the result of a Find. However as you pointed out, Get( FoundCount ) is more readable, what I would call "self-commenting code," whereas with an error code I'd be compelled to include a comment.

  • Like 1

Share this post


Link to post
Share on other sites

Every script step has its error code, even where there is no error, code for that will be "0".

So if after script step FoundRecord you get error code "401", after next script step this number will alter.

Let's look Get (FoundCount) - the result of this operation is much more stable, even when the script in over.

So maybe here you can feel the difference or save your time in future. Get (FoundCount) is more useful when you have several scripts running.

Hope you catch the drill.

Share this post


Link to post
Share on other sites

Not all find errors are 401. There's a few, but one that comes to mind is 400 (find criteria are empty). That will not result in an empty set, but rather a found set of the records before the find was initiated.

I recommend a "belt and suspenders" calculation:

Get ( LastError ) or ( Get ( FoundCount ) = 0 )

Also, keep in mind the OnModeEntry scripts will trigger on a find and the error will return at the beginning of the trigger script.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Who Viewed the Topic

    1 member has viewed this topic:
    jarvphot 
×

Important Information

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