2 Replies Latest reply on Aug 17, 2011 8:12 PM by StanleySilverman

    Script to deal with Find that doesn't Find

    StanleySilverman

      Title

      Script to deal with Find that doesn't Find

      Post

      I'm new to FMP and am working on a database that will allow me to follow patients in an intensive care unit on a daily basis.  I developed a script that will carry over data from the day before to the next day but need a way to deal with what happens if there was no data from the day before.  Here's the current script:

       

      Set Variable [$date; Value: "=" & Get(CurrentDate)-1]

      Perform Find [Restore] where Restore is ICU::Date [$date]

      Contrain Find [Restore] where Restore is ICU::Room# [375]   - this contrains the find to the record that was present yesterday in room 375.

      Duplicate Record/Request

       

      This Script works find if there is a record from the day before to copy.  However, if there is no record I want the script to just generate a new Record with the room number autofilled (Room 375).  If that's not possible I at least want to avoid "No records match this find criteria." window that pops up.

      Any help would be appreciated.

        • 1. Re: Script to deal with Find that doesn't Find
          philmodjunk

          Set Variable [$date; Value: "=" & Get(CurrentDate)-1]
          Perform Find [Restore] where Restore is ICU::Date [$date]
          Set Error capture [on]
          Constrain Find [Restore] where Restore is ICU::Room# [375] - this contrains the find to the record that was present yesterday in room 375.
          If [ Get ( FoundCount ) ]
             Duplicate Record/Request
          Else
             New Record/Request
             Set Field [ICU::Room# ; 375 ]
          End IF

          Note: I wouldn't actually put 375 into either  script step where this is listed literally. That requires changing the script each time you need to do this with a different room3. If you use a variable for the room number, this script can then be modified to work with any specified room.

          • 2. Re: Script to deal with Find that doesn't Find
            StanleySilverman

            Thanks much Phil,

             

            I was workiing on this today and it looks like your solution is similar to what we were working on.  I'll give it a try.

             

            Stan