1 2 3 Previous Next 34 Replies Latest reply on May 6, 2017 11:33 AM by BruceRobertson

    Can't get loop to work properly

    kmicb5

      I'm tweaking an existing database that comes with FM called "Assets". I added a new layout that is list format, shows me all my assets. I have added a check box next to them to be able to select certain records or all or none. The goal is to be able to check-in or out multiple records at a time. So far, I've had 1/3 luck. Below are the tweaked scripts, the first two are selecting all or clearing the checkboxes, which work fine of course.

       

      Selecting All Records:

      Go to Record/Request/Page [First]

      Loop

           Set Field [Assets::CheckBox ; 1]

           Go to Record/Request/Page [Next ; Exit after last]

       

      Deselecting Records:

      Go to Records/Request/Page [First]

      Loop

           Set Field [Assets::CheckBox ; 0]

           Go to Record/Request/Page [Next ; Exit after last]

       

      The existing built-in scripts in the db that are used when "checking out" an asset are an OnEnter and an OnExit script. They of course work for one record. I tried adding a loop to go through all found records that were checked (=1) but it still only does the selected row not by the check mark, but the row that happens to be highlighted even though I have the first steps to enter find mode and perform find before the loop. Here is the semi-working, tweaked OnEnter and OnExit scripts:

       

      OnEnter script "Trigger | On Check-Out Enter Loop":

      Enter Find Mode [ Restore ; Pause Off ]

      Perform Find [Restore] <--and here is where the custom find is entered, which is Assets::CheckBox = 1

      Go to Record/Requests/Page [First]

      Loop

           Commit Records/Requests [With dialog: On]

           If [IsEmpty (Assets::Date Checked Out)]

                Set Field [Assets::Date Checked Out ; Get (CurrentDate)]

                Set Field [Assets::Date Due ; Get (CurrentDate) + 7]

           End If

           Go to Record/Request/Page [Next ; Exit on last]

      End Loop

       

      OnExit script "Trigger | On Check-Out Close Loop":

      Enter Find Mode [Restore ; Pause Off]

      Perform Find [Restore] <--again here is where the custom find is entered, Assets::CheckBox = 1

      Go to Record/Requests/Page [First]

      Loop

           If [$$TRIGGER ; Value: "On"]

           Exit Script [Text Result:  ]

      Else If [IsEmpty (Assets::Date Checked Out Popover) or Assets::Assigned To = "Not Assigned"]

           Set Field [Assets::Date Checked Out ; ""]

           Set Field [Assets::Date Due ; ""]

           Exit Script [Text Result:  ]

      Else

           Set Field [Assets::Date Checked In ; ""]

           Set Field [Assets::Date Checked Out ; Assets::Date Checked Out Popover]

           Set Field [Assets::Date Due ; Assets::Date Due Popover]

           Set Variable [$CURRENT_ASSET_ID ; Value: Assets::ASSET ID MATCH FIELD]

           Set Variable [$CURRENT_DATE ; Value: Assets::Date Checked Out]

           Set Variable [$DATE_DUE ; Value: Assets::Date Due]

           Set Variable [$CURRENT_ASSIGNMENT ; Value: Assets::Assigned To]

           Set Variable [$CURRENT_LOCATION ; Value: Assets::Location]

           Set Field [Assets::Condition ; "Good"]

           Freeze Window

           Go to Layout ["History" (History)]

           New Record/Request

           If [$$PLATFORM = "Phone"]

                Go to Layout ["Asset Details | iPhone" (Assets)]

           Else

                Go to Layout [original layout]

           End If

           Go to Record/Request/Page [Next ; Exit on last]

      End If

      End Loop

       

      Any direction would be great!

        1 2 3 Previous Next