2 Replies Latest reply on Feb 23, 2010 2:49 PM by jforsyth

    Using find data to create a new record, when none are found

    jforsyth

      Title

      Using find data to create a new record, when none are found

      Post

      Having a little trouble figuring this one out.

      I have a basic find script that I want to capture the inputted find data and insert them into into fields in a new record, when no record is found. But I cant figure out the syntax to use with filemaker.

       

      Thanks!

        • 1. Re: Using find data to create a new record, when none are found
          ninja
            

          Howdy jforsyth,

           

          Have your folks enter the find criteria while in browse mode into "find fields".

          Then run your script with th following parts:

           

          Trap the data and clear the find fields:

          SetVariable [ $Name ; Value: Table1::Name ]

          SetVariable [ $Phone ; Value: Table1:: Phone ]

          SetField [ Table1::FindName ; ""]

          SetField [ Table1::FindPhone ; ""]

           

          Perform the find:

          Enter Find Mode

          SetField [ Table1::Name ; $Name ]

          SetField [ Table1:: Phone; $Phone ]

          Set ErrorCapture [on]

          Perform Find []

           

          Check to see if anything was found, if so...exit the script:

          If (Get (FoundCount) > 0 )

               Exit Script

          EndIf

           

          Check to see if none were found, if so...make one:

          If (Get (FoundCount) = 0 )

             New Record/Request

             SetField [ Table1::Name ; $Name ]

             SetField [ Table1:: Phone; $Phone ]

          EndIf

           

          Note that the second "If" isn't formally required...the FoundCount is either 0 or it isn't.

          Note also that any typos in your find fields will now result in new records, or John Smith with a different phone# will result in a second record for him.  make sure that's what you want...

          • 2. Re: Using find data to create a new record, when none are found
            jforsyth
              

            Ahh, I see now. I was trying to trap the data after I performed the search. I set the var's and fields before find mode and It worked great.

             

            Thanks a lot for the help, much appreciated!