5 Replies Latest reply on Feb 16, 2012 8:53 AM by NaturSalus

    Faulty Find Script

    NaturSalus

      Title

      Faulty Find Script

      Post

      Hello,

      In my project the Tool bar is hidden so I have to reproduce the Find capabilities through scripting.

      My current setting is as follows:

       

      From Manual_Detail layout the Find Script is triggered through the Find button.

      From the Manual_Detail layout the Find Script takes the user to the Manual_Find layout where he/she can enter the find criteria.

      Once the find criteria has been entered, the user clicks the Continue button on the Manual_Find layout and the following message pops up:

      would you like to show the found set of records in Form and List view?

      Based on the user choice, the Find scripts takes him/her to the Manual_Form or the Manual_List layout and from there the user can print the record found set using the Current Record Found Set Print script.

      As it is set up, every time that the user carries out a find / search that results in a found set > 1, the message:

      would you like to show the found set of records in Form and List view?

      should always pop up.

      But, it doesn't.

      My problem is that for any find /search where the found set is larger than 1  (more than 1 record in the found set) sometimes the above mentioned messages shows up but most of the time it doesn't and takes me directly to the Manual_Form layout

      So the Find script is for sure faulty but I can't figure aout where.

       

      A hand is requested to make work the Find script consistently.

       

      The main scripts used are the following:

       

      Find Script:

      # Error Handling
      Allow User Abort [ Off ]
      Set Error Capture [ On ]


      Set Variable [ $LastLayout; Value:Get(LayoutNumber) ]
      Perform Script [ “Save TO” ]
      Go to Layout [ LeftWords(Get(LayoutName); 1) & "_Find" ]
      Enter Find Mode [ ]


      Loop


      Modify Last Find
      Pause/Resume Script [ Indefinitely ]
      Perform Find [ ]


      If [ Get(LastError) = 400 ]
      Freeze Window
      Show Custom Dialog [ Title: "No Find Criteria"; Message: "No find criteria was entered."; Buttons: “OK” ]
      Go to Layout [ original layout ]
      Exit Loop If [ 1 ]


      # when no records are found


      Else If [ Get(FoundCount) = 0 ]
      Show Custom Dialog [ Title: "No " & Proper(LeftWords(Get(LayoutName); 1)) & " Found"; Message: "No " & Lower(LeftWords
      (Get(LayoutName); 1)) & " were found. Would you like to redefine your find criteria?"; Buttons: “Yes”, “No” ]
      If [ Get(LastMessageChoice) = 2 ]
      Perform Script [ “Restore TO”; Parameter: $LastLayout ]
      Exit Loop If [ 1 ]
      End If


      # when only one record is found


      Else If [ Get(FoundCount) = 1 ]
      Perform Script [ “Form View” ]
      Exit Loop If [ 1 //one record was found ]


      # when more than one record are found


      Else
      Show Custom Dialog [ Title: "Show as a Form or as a List"; Message: "Would you like to show the found set of records in Form
      or List View)"; Buttons: “Form”, “List” ]
      If [ Get ( LastMessageChoice ) = 1 ]
      Perform Script [ “Form View” ]
      Exit Loop If [ 1 //one or more records were found ]
      End If
      Perform Script [ “List View” ]
      Exit Loop If [ 1 //one or more records were found ]
      End If


      End Loop

       

      Form View Script

      # Error Handling
      Allow User Abort [ Off ]
      Set Error Capture [ On ]


      # found set is shown in the TableName_Form layout
      Go to Layout [ LeftWords(Get(LayoutName); 1) & "_Form" ]
      Pause/Resume Script [ Indefinitely ]


      # back to the original layout
      Go to Layout [ LeftWords(Get(LayoutName); 1) & "_Detail" ]
      Show All Records
      Unsort Records

       

       

      List View Script

      # Error Handling
      Allow User Abort [ Off ]
      Set Error Capture [ On ]


      # found set shown in the TableName_List layout
      Go to Layout [ LeftWords(Get(LayoutName); 1) & "_List" ]
      Pause/Resume Script [ Indefinitely ]


      # back to the original layout
      Go to Layout [ LeftWords(Get(LayoutName); 1) & "_Detail" ]
      Show All Records
      Unsort Records

       

       

      Save TO Script


      # Error Handling
      Allow User Abort [ Off ]
      Set Error Capture [ On ]
      #
      If [ LeftWords(Get(LayoutName); 1) = "Manual" ]
      Go to Related Record [ From table: “Manual”; Using layout: “Manual_saveTO” (MANUALsaveTO) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "Procedure" ]
      Go to Related Record [ From table: “Procedure”; Using layout: “Procedure_saveTO” (PROCEDUREsaveTO) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "ProcedureForm" ]
      Go to Related Record [ From table: “procedure_FORM”; Using layout: “ProcedureForm_saveTO ” (procedureFORMsaveTO) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "ProcedureRecord" ]
      Go to Related Record [ From table: “procedure_RECORD”; Using layout: “ProcedureRecord_saveTO” (procedureRECORDsaveTO) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "WorkInstruction" ]
      Go to Related Record [ From table: “Work Instruction”; Using layout: “WorkInstruction_saveTO ” (WorkINSTRUCTIONsaveTO) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "WorkInstructionForm" ]
      Go to Related Record [ From table: “workI_FORM”; Using layout: “WorkInstructionForm_saveTO ” (workInstFORMsaveTO) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "WorkInstructionRecord" ]
      Go to Related Record [ From table: “workI_RECORD”; Using layout: “WorkInstructionRecord_saveTO” (workInstRECORDsaveTO) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "Document" ]
      Go to Related Record [ From table: “Document”; Using layout: “Document_saveTO Copy” (DOCUMENTsaveTO) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "DocumentForm" ]
      Go to Related Record [ From table: “document_FORM”; Using layout: “DocumentForm_saveTO ” (documentFORMsaveTO) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "DocumentRecord" ]
      Go to Related Record [ From table: “document_RECORD”; Using layout: “DocumentRecord_saveTO ” (documentRECORDsaveTO) ]
      [ Show only related records ]
      End If
      Go to Layout [ original layout ]

       

       

      Restore TO Script


      # Error Handling
      Allow User Abort [ Off ]
      Set Error Capture [ On ]
      #
      Go to Layout [ LeftWords(Get(LayoutName); 1) & "_saveTO" ]
      If [ LeftWords(Get(LayoutName); 1) = "Manual" ]
      Go to Related Record [ From table: “MANUALsaveTO”; Using layout: Get(ScriptParameter) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "Procedure" ]
      Go to Related Record [ From table: “PROCEDUREsaveTO”; Using layout: Get(ScriptParameter) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "ProcedureForm" ]
      Go to Related Record [ From table: “procedureFORMsaveTO”; Using layout: Get(ScriptParameter) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "ProcedureRecord" ]
      Go to Related Record [ From table: “procedureRECORDsaveTO”; Using layout: Get(ScriptParameter) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "WorkInstruction" ]
      Go to Related Record [ From table: “WorkINSTRUCTIONsaveTO”; Using layout: Get(ScriptParameter) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "WorkInstructionForm" ]
      Go to Related Record [ From table: “workInstFORMsaveTO”; Using layout: Get(ScriptParameter) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "WorkInstructionRecord" ]
      Go to Related Record [ From table: “workInstRECORDsaveTO”; Using layout: Get(ScriptParameter) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "Document" ]
      Go to Related Record [ From table: “DOCUMENTsaveTO”; Using layout: Get(ScriptParameter) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "DocumentForm" ]
      Go to Related Record [ From table: “documentFORMsaveTO”; Using layout: Get(ScriptParameter) ]
      [ Show only related records ]
      Else If [ LeftWords(Get(LayoutName); 1) = "DocumentRecord" ]
      Go to Related Record [ From table: “documentRECORDsaveTO”; Using layout: Get(ScriptParameter) ]
      [ Show only related records ]
      End If

       

      Thanks,

      natursalus

        • 1. Re: Faulty Find Script
          philmodjunk

          Can't spot any errors in your script. When the script takes you to form view and you didn't expect it to, what found set do you have? a single record or multiple records?

          • 2. Re: Faulty Find Script
            NaturSalus

            Hello Phil,

            When the script takes you to form view and you didn't expect it to, what found set do you have? a single record or multiple records?

            A single record.


            After reading your question, I run the script in my project 8 times in a row and I din't hav any issues. 

            So I created a new record. Then carried out the script and Bingo the problem was there again.


            I had entered 4 records thant contained the word Manual (Quality Manual; Environment Manual, Food SAfety Manual, OHS Manual) and the new one named Customers Log. I did a find with the word Manual and got just 1 record, the first record entered in the database: Quality Manual.

            I repeated the process with the same number of records, and no problem. Then, I entered a new record that didn't contain the word Manual in its name (Invoices Log). I did a find for Manual, and again the same problem: only 1 record in the found set and was the the first record entered in the database: Quality Manual.


            Thanks,

            natusalus

            • 3. Re: Faulty Find Script
              NaturSalus

               

              The issue appears randomly. I have run the Find script several times with no issues and then all the sudden shows up again. The only thing that repeats always, is that if I do a find for the word "Manual" I always get 1 record and is the first one: Quality Manual, it never gives me: Environment Manual, Food Manual, OHS Manual.

               

              Thanks,

              natursalus

              • 4. Re: Faulty Find Script
                philmodjunk

                Sounds like an indexing problem on the field rather than a problem with your script. If so, performing finds without using your script will show the same problem.

                To rebuild the index of a single field:

                1. Open Manage | Database | Fields and double click the field
                2. Use either the storage tab or the storage options button to turn off indexing.
                3. Exit Manage | Database, then return and turn indexing back on.

                 

                You can also rebuild all your file's indexes by importing all the data into an empty copy (clone) of your file.

                If you have FileMaker 11, you can use Advanced Recovery options to rebuild your file's indexes:

                1. With the file closed, select Recover from the File Menu.
                2. Select "Use advanced Options"
                3. Select only: "Copy File Blocks as-is" and "Rebuild Field Indexes Now".
                • 5. Re: Faulty Find Script
                  NaturSalus

                  Phil,

                  Again, right on the target!

                   

                  Many thanks,

                   

                  natursalus