6 Replies Latest reply on Oct 13, 2014 9:38 AM by usbc

    Setting a field with a Timestamp

    regex

      Hello FM Gurus,

       

      I have a simple solution that students use to check-in and check-out students. I want to use a script that automatically logs everyone out at the end of the day versus having to check each student out. That said, there are only two main fields (statusInDate) and (statusOutDate) that are timestamp fields. I attempted a script to go to that field, conduct a find and then use the insert current date. However, apparently--that was not the correct method. Any thoughts would be appreciated.

        • 1. Re: Setting a field with a Timestamp
          LyndsayHowarth

          Use the Get ( CurrentTimeStamp )

           

          Lyndsay

          • 2. Re: Setting a field with a Timestamp
            regex

            Yes, but what I was looking for is the correct script steps involved.  So far, I am going to the layout, entering find mode to find all the statusOutDate records that are empty and then I want to set the field to the current timestamp (Get(Currenttimestamp).  That said, what should I do after the Perform Find? 

             

            Go to Layout ["Events Layout"] 
            Enter Find Mode
            Set Field [Events::statusOutDate; "="]
            Perform Find
            • 3. Re: Setting a field with a Timestamp
              davidwheelock

              Try this:

               

               

              Go to Layout [ “Events Layout” ]

              Set Variable [ $current.ts; Value:Get ( CurrentTimeStamp ) ]
              Perform Find [ Specified Find Requests: Find Records; Criteria: Events::statusOutDate: “$current.ts” ]

              [ Restore ]

               

              Basically, set a variable containing the current timestamp, then use the variable as your find criteria.

               

              You also canjust perfrom the find without going into find mode, saving a couple of script steps.

               

              Cheers!

               

              Dave Wheelock

              • 4. Re: Setting a field with a Timestamp
                regex

                I just don't understand how that is going to find the empty records and then set the empty records with the $variable

                • 5. Re: Setting a field with a Timestamp
                  davidwheelock

                  Sorry, I misunderstood.

                   

                  The steps below will find all records with no data in the statusOutDate field, then performs a replace script step to insert the current timestamp.

                   

                   

                  Go to Layout [ “Events Layout” ]

                  Set Variable [ $current.ts; Value:Get ( CurrentTimeStamp ) ]
                  Perform Find [ Specified Find Requests: Find Records; Criteria: Events::statusOutDate: “=” ]

                  [ Restore ]

                  Replace Field Contents [ Events::statusOutDate; Replace with calculation: $current.ts ] [ No dialog ]

                   

                  I'm not a fan of using the replace step on a hosted file with multiple users. And, there's no error trapping performed here, so you won't really know if any of the records could not be written to because they are locked, but if you're performing this on a single user file, in FM go, you should be okay.

                  • 6. Re: Setting a field with a Timestamp
                    usbc

                    After you have found the records with the blank statusOutDate ... You can use the script step "Replace Field Contents" to Specify the statusOutDate field and Replace Field Contents. You can specify what you want to go into the field (with or without a warning dialog box).

                    You could use the variable already mentioned or you could use the data in the statusInDate. That way if you forget to do it until a later date it won't appear that your students spent the night in class. Or as David mentioned, while I was typing, if ever you do miss a record because it was in use or you screw up in some other way... you won't have implausible results. You can, of course, run a followup script which just checks that there are nolonger any empty statusOutDate records with a nice congratulations message.

                    1 of 1 people found this helpful