11 Replies Latest reply on Mar 13, 2012 11:00 AM by NathanLucy

    Script that creates new record when Guest logs in

    NathanLucy

      Title

      Script that creates new record when Guest logs in

      Post

      I'm building a database for my wife's counseling practice, where confidentiality is paramount. My goals right now is paperless "intake." When my wife hands a new client a laptop/iPad with the login screen pulled up, they will click "Login as Guest." 

      The Guest account is limited to the "Intake" layout, and can only view the most recent record, thanks to this little expression under Security, which denies access to any record number < the total number of records.

      If ( Get ( RecordNumber )  < Get ( TotalRecordCount ) ; 0 ; 1 ) 

      Here's the problem: If the most recent record has the previous intake's information on it, then the new client will be able to see the previous intake, i.e., confidentiality is broken.

      Here's what I need: When the client logs in as Guest, the database immediately generates a new record. The client only sees a blank layout, and they proceed to put in their information.

      Is there a way to run a script when the Guest (and only the Guest) logs in? And can a script generate a new record?

        • 1. Re: Script that creates new record when Guest logs in
          bumper

          One way to overcome this issue is to create a shadow table of global fields that mimics the actual fields, the patient enters the data into the globals, and by script once it is validated the data can be moved into a fresh empty record, which the patient never sees, and wipes the globals ready for the next patient. This method allows for additional validation of the data while still in the globals. Also if you have FMP Advanced you can put the patient data entry layout into kiosk mode, which allows you to control the user's every action, ie, that can't get to or do anything that you don't allow them to do. 

          • 2. Re: Script that creates new record when Guest logs in
            NathanLucy

            Bumper, thanks you—you've described precisely the solution I'm looking for, thanks in part to PhilModJunk's tips on a previous post.

            That said, I am finding global fields rather...unwieldy. So far, I can only use a global field to repeat data entered in one record throughout all records. But this is what I'm looking for—can you tell me how to get here?

            a shadow table of global fields that mimics the actual fields, the patient enters the data into the globals, and by script once it is validated the data can be moved into a fresh empty record, which the patient never sees, and wipes the globals ready for the next patient

            • 3. Re: Script that creates new record when Guest logs in
              bumper

              In this case you are using the global fields as a temporary repository for the patient data. You will need to create a one for one duplicate set of fields that matches the real data fields. You will want them to start out empty, so either set them to "" when you first start the program by script or remember to clear them before you close the program. Globals retain the last data in them when the file closes the latter is ok, but the former is safer and almost all databases have other golbals that need to for sure to contain the right data so you reset them on startup with the opening script.

              The script to move the data will probably be long, but lots of redundency within, lets say you have one table for patent demographic data, name, birthdate, etc, and another for address, etc. You would create ALl of those fields in your global table, even though they might be in a seperate table. So after you have validated the global fields (no empty required fields, dates in date fields, you would go to the Patient table, create a new record (grab that ID in a variable, $PatientID) and proceed to populate those fields with the global data, when you get to the addresses you would create a new record in the address table, put the $patientID in the patientID foriegn key field and then put the address data in address fields and on down the line.

              When you are through with the very last field just go back and delete the data the global fields (set them to "") and the next person will see nothing but an empty set of fields. I like to make this a seperate script that I can also use as for a cancel button in case the patient has problems or second thoughts. Note you do not need a record in the global table for this to work, it is really better to have zero records at all times, the globals and real data tables do not need to be related for this to work. 

              Your validation can occur at the beginning of the script and just depends on how necessary the data is, you can use conditional formatting to mark the records that must be completed before the data can be submitted. Create a small test file with just one or two fields and tables and get a feel for how this works and then create the real table. Any questions or problems ask away.

              • 4. Re: Script that creates new record when Guest logs in
                NathanLucy

                Bumper, thanks for the help planning this database. This is a great outline of what I want to do.

                • 5. Re: Script that creates new record when Guest logs in
                  NathanLucy

                  Okay, so I'm wondering how to structure this. First of all, when do scripts run? Upon logging in, after some trigger?

                  Second, it sounds like you're suggesting the following. Could you review this plan and field my question under #3?

                  1. Create a global table with no records.

                  2. Write a script to set global field values to "" when Guest logs in.

                  3. Generate a PatientID# unique to this Guest session. Is this another script?

                  4. Write a script to copy the new PatientID# and the current session's global field values to a new record my "Master Client List" table. This script is running while the Guest is editing the global fields.

                  5. Re-use the script from #2 to reset global fields to "" after script from # has copied all of the required global fields to "Master Client List."

                  6. Validation—this can wait until I get the rest up and running.

                  Any feedback would be welcome. I'm trying to grasp how scripts work, and I feel stuck.

                  • 6. Re: Script that creates new record when Guest logs in
                    bumper

                    Okay, so I'm wondering how to structure this. First of all, when do scripts run? Upon logging in, after some trigger?

                    Second, it sounds like you're suggesting the following. Could you review this plan and field my question under #3?

                    1. Create a global table with no records.

                    2. Write a script to set global field values to "" when Guest logs in.

                    I would make a script that does nothing but go from global field to global field and set each with a "". Then you can run it at startup, when the program first runs and again after each patient's data has be entered into the appropiate table.

                    3. Generate a PatientID# unique to this Guest session. Is this another script?

                    No need to as there is no patient record yet. When you have all the data in the globals make a button that goes to a patient layout, creates a new record and since you already have FM creating a unique serial number everytime a new record is created just use that one. 

                    4. Write a script to copy the new PatientID# and the current session's global field values to a new record my "Master Client List" table. This script is running while the Guest is editing the global fields. 

                    Once the new record is created and before the transfer starts put the PatientID int a variable, then if you need to move the data into a related table, you would set the patientID foreign key with the variable, this would relate the "child" tables to the "parent" (patient) table. 

                    5. Re-use the script from #2 to reset global fields to "" after script from # has copied all of the required global fields to "Master Client List."

                    Yes

                    6. Validation—this can wait until I get the rest up and running.

                    You will learn a lot about human nature during this phase...

                    Any feedback would be welcome. I'm trying to grasp how scripts work, and I feel stuck.

                    One way to develop your scripting is to just write down exactly what it is you need/want to do plain english, then look for script steps to "get 'er done" and as you know PhilModJunk is excellent with scripting and calculations, so there is plenty of help should you need it.

                    • 7. Re: Script that creates new record when Guest logs in
                      philmodjunk

                      To expand on the concept of Filemaker scripting, nearly all scripts recreate the steps you take to do the same thing manually with "control" steps Like If and Loop thrown in to enable it to run with minimum help from the user. Often it is helpful to figure out what menu options you would select to do what you want to do, write them down on a piece of paper and then open the script editor to find the script steps that correspond with your menu picks when doing it manually. You'll find that the script steps have very similar names and often open up the same dialog boxes you use when doing the same action manually.

                      • 8. Re: Script that creates new record when Guest logs in
                        NathanLucy

                        I'm making seious progress, but I've hit another snag. I'm working with a slimmed-down prototype database. Now my "Patient Intake" table has two global fields: "Name" & "DOB". I have a script that sets the contents of these fields to $Name and $DOB.

                        I have another script to:

                        (1) access the "Master Patient Database" non-global table,

                        (2) create a new record,

                        (3) "Get" the last record (the newly created on, step 2), and

                        (2) "Replace Field Contents" of MPD::Name with $Name & "Replace Field Contents" of MPD::DOB with $DOB.

                        But instead of modifying only the current (last) record, my script updates every record in the "MPD". I've tried this with local and global ($Name and $$Name) variables, with no success. Any clue what I'm missing?

                        • 9. Re: Script that creates new record when Guest logs in
                          philmodjunk

                          If you were to look up Replace Field Contents in FileMaker help, you'd find that that is exactly what Replace Field Contents is intended to do--update a specified field for every record in your current found set. Instead, use set field and this should work for you.

                          • 10. Re: Script that creates new record when Guest logs in
                            bumper

                            Whoa, serious overkill here.

                             

                            1. Patient puts data into global fields, then clicks on button [submit] which starts the script and sets variables

                            Set variable [$Name;"Name_g"]

                            Set variable [$DOB; "DOB_g"]

                            2. goto layout Master Patient (this can be a one use layout with just the fields you need, you just have to get to a patient layout)

                            3. create new record. (this gives you a brand new spanking clean empty fields record, save for the PatientID which should be an auto-enter process)

                            4. set fields with the data.

                            Set field [Patient::Name; $Name] 

                            Set field [Patient::DOB; $DOB

                            5. go to layout Globals

                            6. Perform script [delete data] script

                            7. ready to start all over again...

                             

                            Steps 1-6 are all one script, the field with the suffix are globals the suffix is just so you'll know at a glance, you don't really have to use the suffix for this to work. As you have found out the Replace command is very powerful and can screw up the works really really quick and there is no undo. You'll learn how to harness this step later.

                            • 11. Re: Script that creates new record when Guest logs in
                              NathanLucy

                              I've got a working Intake Form! It's totally confidential, too. Thanks, Bumper & PhilModJunk. Y'all have been really helpful. I may post a link to my next post if y'all want to see how things go from here. Regardless, thanks guys. This forum community is awesome.