6 Replies Latest reply on Dec 18, 2014 4:33 PM by philmodjunk

    Using "Get (LastError)" to set a variable to 0?



      Using "Get (LastError)" to set a variable to 0?


      I'm trying to set a variable (to zero) in response to a "no records found" 401 error, but can't get it to work. I'm attaching a screenshot of the full script as I cannot export the script to text.

      Is this possible? If so, what am I doing wrong?


        • 1. Re: Using "Get (LastError)" to set a variable to 0?

          There isn't anything obviously wrong with your script. Why do you think there's something wrong? What is the script doing instead of what you expect?

          As for setting the $NothingFound variable, you could only have one script step to set it, and place that Set Variable step outside the If block: Set Variable [$NothingFound; Value:Get ( FoundCount )] — since the found count will be 0 in the event of a 401 error.

          • 2. Re: Using "Get (LastError)" to set a variable to 0?

            The constrain found set with no criteria immediately following the Perform Find  makes no sense. I'd remove it.

            • 3. Re: Using "Get (LastError)" to set a variable to 0?

              Thanks for your ideas, but here's the problem (and it remains): The script passes along the correct FoundCount for anything >1, but it passes along no data when there are no found records. My original script did not use an if block, as you suggest I should try. My attempt at implementing the if block was in reaction to the failure of the FoundCount step to pass ANY data along when it found no records.

              More specifically, this script connects two related databases; it receives a value (on the pasteboard) from the second database. When there are no found records, this script passes BACK the same pasteboard value as it received.


              (I did remove the extraneous constrain found set–thanks for catching that PhilModJunk!)

              • 4. Re: Using "Get (LastError)" to set a variable to 0?

                Why would you expect Get ( FoundCount ) to return anything but 0 if there are no found records?

                And I will repeat that Constrain Found Set[] does nothing here and may be why you can't capture the error code in a variable as the set variable step should be placed immediately after the perform find step.

                • 5. Re: Using "Get (LastError)" to set a variable to 0?

                  PhilModJunk: I don't expect anything other than 0. What I'm getting, however, is not "0," but nothing–no data whatsoever passed from Get ( FoundCount ). And I did delete the Constrain as you suggested; thank you again.

                  If I replace the If block with a custom dialogue step, it works as expected (when there is a 401 error, it displays the custom dialogue). However, I can't get the 401 event to either return "0" for Get ( FoundCount ), nor –as I'm clearly trying to cludge together with the script above– can I work around it (at least not as it's structured above).

                  Everything else works as expected: as long as the data set >1, the script reports the correct number and all is well. But when there's no found set....

                  Rick Whitelaw: The paste is a received value (stored on the pasteboard) from a second database. The problem is that when there are no found records, this script passes BACK the same pasteboard value as it received, rather than using the pasteboard data to perform a search, and return the number of records that match that search.


                  The first database is a list of music faculty, each with a specialty instrument. The second database is a list of students auditioning on said instruments on different audition days. This script is the middle of three that report the number students signed up in each faculty's specialty: The First script passes the named specialty from the 1st database, and this (2nd) script pastes the specialty and sets the audition day for the find request in this database. It then passes the Get ( FoundCount ) to the Third script via the pasteboard, which simply pastes the number in the appropriate box in the first database.


                  • 6. Re: Using "Get (LastError)" to set a variable to 0?

                    Did you perhaps set up a calculation field with Get ( FoundCount )? Unless you specifically define it to be an unstored calculation, that field won't update when the found set changes and that could leave you with an empty field.

                    I suggest comparing your script to the scripted find examples found here: Scripted Find Examples

                    Note that copy and paste steps are not used in these examples as there are better options unless you are pasting criteria from a source outside of FileMaker.