6 Replies Latest reply on Jun 2, 2010 9:19 AM by Madpearl

    coping with a failed search in a script

    Madpearl

      Title

      coping with a failed search in a script

      Post

      I have an existing script which pastes a code number into another database and performs a find. No problem there.

       

      However, the function of the script has now increased and I want it to perform something else if the find comes up with no results and offers the "cancel/continue/modify find' dialogue.

       

      Basically I need the script to say 'if the result of the find is incomplete, go and search in the other database'.

       

      Thanks to all in advance. (especially to PhilModJunk who has helped in the past. Do you ever sleep?)

        • 1. Re: coping with a failed search in a script
          ninja

          Howdy Madpearl,

           

          I think you're looking for a script function like:

           

          If ( Get(FoundCount) = 0 )

               *****Do this other thing***

          EndIf

          • 2. Re: coping with a failed search in a script
            Madpearl

            Thank you Ninja for your speedy response, that looks on the right wavelength.

             

            It's rather annoying that all the "Get" functions don't show in the "all functions by name" view.

             

            However, I have put it in my script – see below – and the script is still stopped by the dialogue window "cancel/continue/modify". Can I bypass the dialogue window?

             

            Go to Layout ["Data entry"]
            Enter find mode
            Paste [Select: conferences::unique"]

            Peform find

              If(Get (FoundCount) = 0

              Perform Script ("start new contact" from file: "Contacts"
            Else

            Perform Script: "sort by capacity"

            Perform Script: "go to list layout"

            End If

             

            Madpearl

            • 3. Re: coping with a failed search in a script
              ninja

              Howdy Madpearl,

               

              Try:

               

              Go to Layout ["Data entry"]
              Enter find mode
              Paste [Select: conferences::unique"]

              Set ErrorCapture [on]

              Peform find

              If(Get (FoundCount) = 0

                Perform Script ("start new contact" from file: "Contacts"
              Else

                  Perform Script: "sort by capacity"

                  Perform Script: "go to list layout"

              End If

               

              Also, strongly consider using "Set Variable" and "SetField" instead of Copy and Paste.  Copy and Paste interact with the user's clipboard and can cause annoyance and/or problems down the road...leave the clipboard alone by using these other commands.

              • 4. Re: coping with a failed search in a script
                Madpearl

                That did it, Ninja.

                 

                Thank you very much.

                 

                I will have a look at using "set field" etc. I have noticed it on this forum several times and get the impression it's the way to go.

                • 5. Re: coping with a failed search in a script
                  philmodjunk

                  Copy and Paste were once the only way to move data from one field/record to another. They're still with us to provide backwards compatibility during file conversions and for certain specialized uses like moving data to and from a different application.

                   

                  Set Field and Set Variable are better options than copy/paste steps for the following reasions:

                   

                  Copy and Paste require that the referenced field be present on the current layout. If you edit you layout at some point in the future, your script will fail silently (no error message pops up and script does not halt). You won't know why the script isn't working until you figure out that a value wasn't copied or pasted.

                   

                  Copy replaces the contents of the system clipboard with the data copied by your script. This ticks off your users when they've copied info to the clipboard only to have it mysteriously change to some other value whenever your script executes.

                   

                  Set Field and Set Variable avoid both these issues.

                  • 6. Re: coping with a failed search in a script
                    Madpearl

                    Thanks, Phil.

                     

                    It wouldn't be the same if you didn't comment.

                     

                    I am going to have a read about these functions and how to apply them. It looks a worthwhile method to put into practice.

                     

                    Peter (Madpearl)