3 Replies Latest reply on Jan 27, 2011 2:07 AM by DamonCasey

    Perform Find With No Found Records Returns 0 Not 401

    DamonCasey

      Title

      Perform Find With No Found Records Returns 0 Not 401

      Post

      I'm developing a system where a scripted find with Set Error Capture on is returning 0 when no records are found. This should return 401. I've tried searching different fields with the same results. I've created a new file with the same script and that does return 401 as expected. Any ideas why the original file doesn't return the correct error code?

        • 1. Re: Perform Find With No Found Records Returns 0 Not 401
          philmodjunk

          With error capture on, a find that fails to find any records will return 0 records. This is expected behavior.

          If you want to see all records if no records are found, your script will need to check to see if any records were found and use Show All records if none were found.

          If you want to return to your original found set, life get's difficult as this is not simple to do.

          • 2. Re: Perform Find With No Found Records Returns 0 Not 401
            raybaudi

            @Phil

            The expected behavior is that the last ERROR number was 401.

            @DamonCasey

            Are you sure to get the very last error ? IOW, there are other steps after your Find that could return a 0 error ?

            • 3. Re: Perform Find With No Found Records Returns 0 Not 401
              DamonCasey

              Thanks PhilModJunk and raybaudi for your replies.

              raybaudi understands the issue and here is the script I'm running:

              Set Error Capture [On]
              Enter Find Mode []
              Set Field [ORD__tog::Status; "Cancelled"]
              Perform Find[]
              Set Variable [$LastError; Value:Get ( LastError )]
              Exit Script [Result: $LastError]

              $LastError should be 401 when no records are found and 0 when records are found. I've tracked the issue down to an OnRecordLoad script trigger on the layout that suppresses the 401 error. If I switch the script trigger off the script returns 401 as expected. I'm now using a layout based on the same Table Occurrence that doesn't use OnRecordLoad to perform this script and then return to the original layout afterwards.

              I've submitted a feature request for a new script step called Set Script Triggers that would allow us to control activation and deactivation of script triggers that would stop this from happening. I could use a global variable to simulate this but it wouldn't stop the error code suppression and the script step would be the best option.

              Thanks for your help.