3 Replies Latest reply on Jun 29, 2011 11:59 AM by VinayKhanna

    Script for Capturing and Using Find Data to create a new record when none are found

    VinayKhanna

      Title

      Script for Capturing and Using Find Data to create a new record when none are found

      Post

      I have seen this addressed on the boards but I don't understand the syntax to correctly input the Set Field Data.

      Using FMP 11.x

      Simple Problem.  There are four fields with user input data (e.g. FName, LName, DOB, UID) and a system generated Auto-indexed Record Key.  Before a new record is added to the Database, I want to check whether a record with this set of criteria already exists in the database.  If no match is found, then a new record is added and the next sequential Record Key is generated.

      I created two tables related via the Record Key.  Table1 with (FName, LName, DOB, UID, Record Key) and Table2 with (TFName, TLName, TDOB, TUID, g_TFName, g_TLName, g_TDOB, g_TUID, Record Key) the last four _g_fields being Global Fields to pass the parameter data between a Find and Browse Mode.

      The Script Opens with Table2 in Browse Mode and the data entered in the TFName, TLName, TDOB, TUID fields is copied into the Global Fields.  Then Layout for Table 1 is called and entered in Find Mode, the Data from the four fields in Table2 is copied into the four fields in Table1. Then the Record Key is checked for a >1 value and if true, the Record Key is saved for another action.  If the Record Key is False(=0); then a New Record Request is created in Browse Mode and the Data Copied back to Table1 (FName, LName, DOB, UID) and the new Record Key is generated along with the newly created record.

      By pausing the Script I can see the data move from the initial entry to the find in Table 1, but the (If Record Key>1) test does not seem to produce the expected result.  

      Any help is greatly appreciated!

      The example posted is shown using just two fields for simplicity.

      The corrected FindID Script is now posted and works reliably.  This issue is SOLVED.

      FindID_Script.png