2 Replies Latest reply on Nov 9, 2011 10:20 PM by ArturoDeguza

    How do I detect an empty set after a search?

    ArturoDeguza

      Title

      How do I detect an empty set after a search?

      Post

      Hello All:

       

      I am trying to branch off my script with an if statement depending on the results of a search.

       

      What condition would I use for the if statement? I thought FMP returns an "401" error code when search returns no results, and I am currently using it but it is not working.

       

      Here is my script:

       

      Set Error Capture [ On ]

      Go to Layout [ “search_layout” ]

      Enter Find Mode[ Pause ]

      Set Field [ PSC_ECO::gErrorCaptureField; Get (LastError) ]

      If [ PSC_ECO::gErrorCaptureField = 401 ]  

             Show Custom Dialog ["Not Found"; "This ECO does not exist. Are you sure your entries are correct?"]

      Else  

             Go to Layout [ “PSC_ECO” ]

      End If

       

      Thanks!

       

      Deguza

       

        • 1. Re: How do I detect an empty set after a search?
          philmodjunk

          Perhaps its a typo, but your example script never actually perfomrs the find, remaining in find mode.

          Go to Layout [ “search_layout” ]
          Enter Find Mode[ Pause ]
          Set Error Capture [ On ]
          Perform Find []
          Set Field [ PSC_ECO::gErrorCaptureField; Get (LastError) ]
          If [ PSC_ECO::gErrorCaptureField = 401 ] 
                 Show Custom Dialog ["Not Found"; "This ECO does not exist. Are you sure your entries are correct?"]
          Else 
                 Go to Layout [ “PSC_ECO” ]
          End If

          Should work, but 401 is not the only error that can be returned by Perform Find. Leaving all fields blank, for example returns a different error code. You may want to check for any error code returned except 0 or you may want to use Get ( FoundCount ) to test to see if performing the find pulled up any records or not.

          • 2. Re: How do I detect an empty set after a search?
            ArturoDeguza

             Thank you.

             

            Leaving the "Perform Find []" out was not a typo, but ignorance :) I constructed a few databases a few years ago. Then have not touched any for four years. I am discovering that I forgot most of what little I knew...

            I like your suggestion about using "Get (FoundCount)". I'll try to use it and see if I can make it work.