14 Replies Latest reply on Jun 25, 2010 4:46 AM by ninja

    Login History



      Login History


      I would like to know when I last opened my program in FMP 9.  


      Currently, I open the program to a menu screen that shows the current date and time.  I would like to add a field showing when I last opened the program.


      Thank you in advance,



        • 1. Re: Login History

          If by "program", you mean your database file, you can write a script that logs the current date in a date field each time you open the file.


          To set up a script to run each time you open the file, select that option in File Options.

          • 2. Re: Login History
            Steve Wright

            You can simply add this field to your database, then use a script step to set the date



            Add a new field to record the last access date.


            Create A script with the following script step

            Set Field [ table::datefield ; Get(CurrentDate) ]



            The script can set to run on opening the file by going to 

            File > File Options

            Then choosing to Perform the above script on opening the file.


            If you already have a script running on file open, just add that script step in place & the field of course..


            Edit : there I go again... duplicating an answer :-)

            • 3. Re: Login History

              Both of you have provided the perfect answer.  I would only add that it would be wise to include in File Options upon open to go to the correct layout or to add Go To Layout [ layout based upon the same table occurrence as this field ] to the beginning of your script.

              • 4. Re: Login History
                Steve Wright

                True, of course if its for a single user only and doesn't need to track login history (i.e via a related table) the field could also be set to global storage

                • 5. Re: Login History

                  It seems to me that in these solutions the date field is overwritten on the moment the file opens. Thus, the user will see the current date instead of the last used date.


                  I would suggest something like this:


                  In startup script:

                  Set Variable [$$DateTime; Value:Get ( CurrentTimeStamp )]


                  In shutdown script:

                  Set Field [Database::TimeStampField; $$DateTime]

                  • 6. Re: Login History

                    Wow David40,


                    A lot of answers from very knowledgable folks...nice.


                    I, personally, would set up another table "Login History"

                    and on startup, run a script that looks like


                    GoToLayout ["Logins" (Login Hitory) ]

                    New Record Request

                    GoToLayout [ the layout you want to start on here]


                    In the Login History table, have three fields:

                    Account (autoenter Get(AccountName) )

                    LoginTime (autoenter Get(CurrentTimeStamp) )

                    Logout time


                    Then have a script that runs on logout that looks like:

                    GoToLayout ["Logins" (Login Hitory) ]

                    Show All Records

                    Sort Records (sort by LoginTime, descending)

                    GoToRecord/Request/Page (Last)

                    SetField [ LogoutTime ; Get(CurrentTimeStamp) ]


                    This assumes of course that you are the only user.  If there are multiple users, you'll want to put a find in your logout script to limit it to the user's account name.


                    My two cents...

                    • 7. Re: Login History

                      Thank you very much for all your suggestions!


                      Unfortunately, at my present level of understanding of FMP 9, I am not sure what you are saying and suggesting.  It seems very complex.


                      Thank you, again.



                      • 8. Re: Login History

                        Depending on how much information you need stored, it may be easiest to simply follow SWS's first post.

                        What they are describing is some simple scripting, however, if you have not done any scripting before it might seem confusing.  A script is a set of instructions that developers use to minimize repeatitive or complex tasks.  If you want to keep a log of all the users that use the database, you could have a layout in which you enter the information each time (not good :smileysad:), or you could have a script that does that for you (good:smileyvery-happy:).  The script will get all the required information and put it where you want it.


                        My recommendation for learning scripting is to create some new files from the templates Filemaker provides.  Look at the provided scripts and try to understand how they work.  Think through them logically and don't be afraid to write them down in normal speak (ie. go to my login layout, get the current date, place date in date field, get the current time, place time in time field, get account name, place account name in account field etc etc) then try to translate this into scripting steps.


                        Scripts can be called in a few different ways.  The most common is when some pushes a button and then the script steps are followed.  However, when you are doing something like keeping track of log in's you can have Filemaker do this everytime the file opens.  This is what they are referring to.  Create the script in the scriptmaker, then in the File Options where I believe it says Run Script on Startup, select that script you just created.



                        • 9. Re: Login History

                          Nice description craig5005.

                          • 10. Re: Login History

                            To PhilModJunk, SWS, Ninja, Craig5005 and others, thank you very much.


                            I have worked on the script most of today and, unfortunately, I have yet to reach success.  I have tried writing all the different scripts that were suggested, but to no avail.  I believe the problem is not understanding the suggestions.  For example, when Ninja writes "... Set Field [LogoutTime; Get(currentTimeStamp) ]", I cannot find the "Get(currentTimeStamp)".


                            Also, I assume that I need a field in my login screen that shows the last logout date and time.  When I try to add the field, FMP cannot find a related table.


                            Just for reference purposes, when I open my file, it opens to a menu screen that allows me to go to several different layouts.  It also has the current date and current time.  When I am done working in whatever layout, I return to this screen and hit an "Exit" button to close the file.


                            This is nothing important and does not affect the file.  Its just something I thought would be nice and allow me to practice writing scripts.


                            Unfortunately, FMP is not taught in Central Oregon in any college, high school or old folks home.  Everything I have learned was from the kind folks in this Forum and a couple of FMP 9 manuals.


                            Also, I am running on a Mac with Snow Leopard (10.6).


                            Thanks again!



                            • 11. Re: Login History
                              Steve Wright

                              Firstly, hbrendel is absolutely correct.


                              Using what I originally posted, you would never get to see the date, it would always be over-written unless you intercepted it first, DOH ! maybe I should give up on the late night posting... but here I am doing it again..  This time I will think before I hit the post button.


                              hbrendel has hit the nail on the head with the easiest implementation, but if you need more detail, then Ninja's is the way to go.


                              So how to set that up..


                              Create the field, Im assuming you already know this part, but you may want to change the field to a global, in which case go to manage databases, locate the field and choose Options (lower right) Then click Storage and check 'Use global storage'  This allows the field to be referenced / set from anywhere



                              1. Go to Scripts > Manage Scripts

                              2. Create a new script named something like STARTUP

                              3. Down the left, look for Set Variable  (double click it)

                              4. In the lower right choose Specify (with the set variable highlited)

                              5. Under name put $$DateTime

                              6. Under Value put  Get ( CurrentTimeStamp )  

                              note : functions such as these can be found in a list by clicking on Specify next to the Value.

                              There you will see an area with fields, operators, functions and the area where you put your calculations.

                              7. Close and save


                              Now Create another new script for EXITSCRIPT

                              1. Down the left, look for Set Field  (double click it)

                              2. In the lower right choose Specify target field and select the field you are using to store the timestamp

                              3. Again in the lower right choose Specify next to Calculated result 

                              4. In the main text area put $$DateTime

                              5. Close and save...


                              Now Go to File > File Options and choose these scripts for your startup / exit scripts.


                              Notes : 


                              $$DateTime is a global variable, the current timestamp will set on startup.

                              The field will remain with the last opened date, so you can see it  (my mistake there)

                              On closing, the value stored in $$DateTime will be copied into the field, ready for the next time you open the file.


                              Now, if I have missed anything.. Im sorry but its late again :-P  Ill use that excuse a few more times

                              • 12. Re: Login History

                                David, you will want to create a "Login" table to hold this data.  Then within this table, make a few fields; name, date, and time (or whatever you want to call them).  Then make a new list layout and add these 3 new fields.

                                On a side note, remember to create a button that directs you to this layout so you can view your last log ins.


                                Now for the scripting side...... I see that SWS just responded to your post with scripting instructions.  Unnecessary to repeat.


                                The FM forum is great isn't it.  When I was first learning, I turned to the forum quite a bit and always received great help.

                                • 13. Re: Login History



                                  Thank you everyone for staying with me on this adventure.  SWS's step-by-step instructions helped me understand what everyone else was saying.  I was able to perform the task on the first try without an error message.  This has been a great learning exercise!  


                                  Thank you again!



                                  "... a very happy camper in Central Oregon ..."

                                  • 14. Re: Login History

                                    Thanks, SWS, for the follow through.


                                    One of my guys was out yesterday and I was too busy to check in here.  Thanks for taking the time for the step-by-step.