3 Replies Latest reply on Jan 10, 2011 10:00 AM by philmodjunk

    Previous Record

    lynton

      Title

      Previous Record

      Post

      I have agents that have approximately 200 records each. - As they log out of the database - when they sign back in how can it automatically go to the last record they were on (i.e) below

      John on record -#12, logs out...logs back in and it goes back to record-#12

      Thx

        • 1. Re: Previous Record
          philmodjunk

          Create a record for each agent.

          Set up a script that is set in File Options to run when the file is closed that logs the ID of the current record in that table. (If each agent logs in with a different account name, this info can be used to identify which agent is logging out.)

          Set up a second script to run when the file opens that looks up the ID recorded for this agent and then performs a Find to pull up this record.

          • 2. Re: Previous Record
            lynton

            Is there somewhere I can read on how to write this script

            • 3. Re: Previous Record
              philmodjunk

              You can right in this post. Unless we know the poster is very new to FileMaker, we sometimes post a general outline of the solution that a knowledgeable Filemaker developer can follow to solve their problem. If you get such a post and can't understand it, please feel free to respond back with questions (as you just did) and then we can elaborate in more detail.

              You really need two scripts--one to save that most recent record and one to return to it. Both assume that each user has their own unique account that they use with their password to access the system.

              Your table where you want to log the ID of the current record needs a serial number field for this to work. If You haven't defined one, you'll need to add one and update your existing records to have this serial number field. (Replace Field Contents can be used to load this field with a serial number and update your serial number field's "next value" setting at the same time.)

              Let's call the table, YourTable and this field, SerialID.

              Define a new table, CurrentRecordLog with two fields:

              AccountName (text)
              SerialID (Number)

              Now your log current record script can be written like this:
              Go To Layout [//select a layout that refers to YourTable]
              Set Variable [$SerialNumber ; Value: YourTable::SerialId ]
              Go To Layout [CurrentRecordLog]
              Enter Find Mode [] //clear pause check box
              Set Field [CurrentRecordLog::AccountName ; Get ( AccountName ) ]
              Set Error Capture [on] //keeps error dialog from appearing if no records are found
              Perform Find []
              If [ Get ( FoundCount ) = 0 /* no records found, first time this user's current record is being logged */]
                 New Record/Request
                 Set Field [CurrentRecordLog::AccountName ; get ( AccountName ) ]
              End IF
              Set Field [CurrentRecordLog::SerialID ; $SerialNumber ]
              Go To Layout [original layout]

              Select File Options from the File menu and specify that this script be run each time the file is closed.

              Now the reverse opration is needed for when the file is opened:

              Go To Layout [CurrentRecordLog]
              Enter Find Mode []
              Set Field [CurrentRecordLog::AccountName ; get ( AccountName ) ]
              Set Error Capture [on]
              Perform Find []
              Set Variable [$SerialNumber ; value: CurrentRecordLog::SerialID ]
              Go To Layout [//select layout based on YourTable]
              Enter Find Mode []
              Set Field [YourTable::SerialID ; $SerialNumber ]
              Perform Find[]

              This creates a found set of a single record--which should be OK if your layout is intended for Form View. If this needs to make the current record part of a found set of more records, a more sophisticated pair of scripts would be needed.