3 Replies Latest reply on Dec 3, 2013 6:43 PM by philmodjunk

    Using A Loop to Search

    CharlesAdams

      Title

      Using A Loop to Search

      Post

           I am new to filemaker pro  and am stumbling my way through creating a script. I am setting a variable to a known value, then going to another table to search trough the records for the first record that has a matching value in one of its fields. Starting with got to record[first] i have started a loop with an if statement looking for exact[variable ; table field ] which causes it to exit loop if it is equal, else go to the next record. This has caused it to get stuck in an infinite loop if there is no matching value in any records, i have tried to escape this problem by adding another if statement that when Last[tablerecordID] it exit loop if Last[tablerecordID]. Ok, This is the script i  have so far. It works, but is easily broken. Thanks for ideas/help!!

             Find Web Item

      If [ IsEmpty ( Customer Sales Order::Temp_Manufacture ) or IsEmpty ( Customer Sales Order:: Temp_TwineSize ) or IsEmpty ( Customer Sales Order::Temp_MeshSize ) or IsEmpty ( Customer Sales Order::Temp_Color ) or IsEmpty ( Customer Sales Order::Temp_Length ) ]

      Beep

      Show Custom Dialog [ Title: "Input Data Needed"; Message: "You must fully describe web to be

           selected"; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ] Halt Script

      End If

      Set Variable [ $Manufacture; Value:Customer Sales Order::Temp_Manufacture ]

      Set Variable [ $SalesOrderId; Value:Customer Sales Order::Id ]

      Set Variable [ $WebDescription; Value:Customer Sales Order::Temp_WebDescription ]

      Go to Layout [ “Web Inventory” (Web Inventory) ]

      Go to Record/Request/Page

           [ First ] Loop

      If [ Exact ( $WebDescription ; Web Inventory::Description ) ]

      Exit Loop If [ Exact ( $WebDescription ; Web Inventory::Description ) ]

      Else

      Go to Record/Request/Page

           [ Next ] End If

      If [ Last ( Web Inventory::Id ) ]

      Exit Loop If [ Web Inventory::Id ]

      End If End Loop

      If [ Exact ( $WebDescription ; Web Inventory::Description ) ]

      Set Variable [ $RetailPrice; Value:Web Inventory::RetailPrice ]

      Set Variable [ $ShippingHandling; Value:Web Inventory::ShippingHandling ]

      Set Variable [ $WebSerialNumber; Value:Web Inventory::SerialNumber ]

      Delete Record/Request

      [ No dialog ]

      Go to Layout [ “Sales Order Field” (Sales Order Field) ]

      New Record/Request

      Set Field [ Sales Order Field::SalesOrderIdFk; $SalesOrderId ]

      Set Field [ Sales Order Field::InventoryIDNumber; $WebSerialNumber ]

      Set Field [ Sales Order Field::Description; $WebDescription ]

      Set Field [ Sales Order Field::RetailPriceLookup; $RetailPrice ]

      Set Field [ Sales Order Field::ShippingHandlingPriceLookup; $ShippingHandling ]

      Go to Layout [ original layout ]

      Clear [ Customer Sales Order::Temp_Manufacture ] [ Select ]

      Clear [ Customer Sales Order::Temp_TwineSize ] [ Select ]

      Clear [ Customer Sales Order::Temp_MeshSize ] [ Select ]

      Clear [ Customer Sales Order::Temp_Color ] [ Select ]

      Clear [ Customer Sales Order::Temp_Length ] [ Select ]

      Commit Records/Requests Else

      Go to Layout [ original layout ] Beep

           December 3, 2013 12:59:57

           Adams Enterprises, Inc..fmp12 - Find Web Item -1-

      Find Web Item

           December 3, 2013 12:59:57

           Adams Enterprises, Inc..fmp12 - Find Web Item -2-

      Show Custom Dialog [ Title: "Web not Found"; Message: "Currently this is not in inventory"; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]

      End If