6 Replies Latest reply on Mar 14, 2012 3:19 PM by hobbiesdeveloper

    Need help with "No Records" Error handling for Perform Find Script Function

    hobbiesdeveloper

      Title

      Need help with "No Records" Error handling for Perform Find Script Function

      Post

      Hello,

       

      Could someone please help me with getting a way to handle the error caused by Perform Find script function not finding the record?

       

      I would like a way to be able to somehow output a list of what records weren't able to be found in a loop?

      Thanks.

        • 1. Re: Need help with "No Records" Error handling for Perform Find Script Function
          philmodjunk

          "What records weren't able to be found" would be all the records in your table. And what would be the function of that "Loop"?

          • 2. Re: Need help with "No Records" Error handling for Perform Find Script Function
            hobbiesdeveloper

            This is just for the records that weren't able to be found, i'm using the "Product::__kp_ProductID: [$find] Criteria inside the Find Request. The find request has the product id number which is received from a user input. When a user inputs the wrong number and hits Find, it will pop up an error stating to cancel or continue the script. Is there a better way to handle this problem, i would like to be able to notify the user better?

            • 3. Re: Need help with "No Records" Error handling for Perform Find Script Function
              philmodjunk

              I'm not clear on what you mean by that. If you had 5 products in your table with products numbered 1, 2, 3, 4, 5, and your user specified Product number 6. "just the records that weren't able to be found" would be all 5 product records as NO product records would have been found.

              I prefer not specify criteria inside the perform find step. There's nothing really wrong with that, but using the method I prefer and will demonstrate in this post makes it easier to see what criteria was specified in the find when you review the script.

              Loop
                 Show Custom Dialog ["Enter a Product ID number" : Input Field: YourTable::globalField ]
                 Exit Loop If [ Get ( LastmessageChoice ) = 2 //Cancel was clicked ]
                 Enter Find Mode[]
                 Set Field [Product::__kp_ProductID ; YourTable::globalField ]
                 Set Error capture [on]
                 Perform Find[]
                 Exit Loop if [Get ( FoundCount ) ]
              End Loop

              This script will only work if YourTable::globalField has global storage specified

              You might want to consider a design change for your layout where the user selects a product from either a value list of products or a search portal of product names/descriptions. That option precludes the possibility that they might enter a product ID that does not exist in the table.

              • 4. Re: Need help with "No Records" Error handling for Perform Find Script Function
                hobbiesdeveloper

                This definitely works better than what I have setup but there is one more step that needs to perfom. I need to have it output a message stating that record 6 was not found, how would you implement that inside the code?

                For example if you have 1 - 1000 records and you tried to find 1025 which is definitely not there, it would output a message with the part number that couldn't be found, this is relevant inside a loop that checks for product id's for several items in a database and would be helpful to output a message at the end stating which items weren't able to be found?

                 

                Thanks for all your help.

                • 5. Re: Need help with "No Records" Error handling for Perform Find Script Function
                  philmodjunk

                  Loop
                     Show Custom Dialog ["Enter a Product ID number" : Input Field: YourTable::globalField ]
                     Exit Loop If [ Get ( LastmessageChoice ) = 2 //Cancel was clicked ]
                     Enter Find Mode[]
                     Set Field [Product::__kp_ProductID ; YourTable::globalField ]
                     Set Error capture [on]
                     Perform Find[]
                     If [Get ( FoundCount ) ]
                         Exit Loop if [True ]
                     Else
                         Set Variable [$$NotFoundList ; List ( $$NotFoundList ; YourTable::globalField ) ]
                         Show Custom Dialog [ Quote ( YourTable::globalField ) & " could not be found." ]
                         Exit Loop If [ Get ( LastmessageChoice ) = 2 //Cancel was clicked ]
                     End If
                  End Loop

                  Using the global variable $$notFoundList like this results in a return separated list of ID's not found where each time you run this script and fail to find a record, the ID number specified is appended to the end of the list.