3 Replies Latest reply on Oct 14, 2013 9:01 AM by philmodjunk

    Button (or Script) to insert username, time and date into field

    RickDearden

      Title

      Button (or Script) to insert username, time and date into field

      Post

           Hi all,

           I'm a bit stumped trying to insert a username, current time and date into a field. Obviously you can do this by using the keyboard shortcuts but that involves our users remembering the sequence and then remembering to press spacebar in between each one. I just want to create a button which does this either by invoking a script or just by a simple button action from the 'Button Setup' menu.

           Can anyone help me here? I suspect it's something to do with the Get commands but I don't know how to merege them into one, put a comma and space between them and then put them in a specific field all with one press.

           Any ideas would be most welcomed!

           Many thanks in advance.

           Rick.

        • 1. Re: Button (or Script) to insert username, time and date into field
          philmodjunk

               I would not insert Username, time and date all into the same field. I'd insert the username into a text field and the date/time into a timestamp field. And in some cases, I might even insert date and time into separate date and time fields.

               Set field [ YourTable::userName ; Get ( UserName ) // but you might want, instead, to use Get ( accountName ) ] **
               Set Field [ YourTable::Timetampe ; Get ( CurrentTimeStamp ) ]

               And you may find it useful to set up auto-enter field options on these fields such that this data automatically entered into each new record. Then simply creating a new record enters this data and no script or button is required.

               **A User name is specified in preferences. An Account name is specified in Manage | Security. One is often confused with the other but they are not exactly the same thing.

          • 2. Re: Button (or Script) to insert username, time and date into field
            RickDearden

                 Hi Phil,

                 Thanks for the quick reply.

                 The solution you propose means adding a few new fields into my tables if I'm interpreting it correctly.

                 The data I need is just going to be used to insert text into a 'Notes' field which already has other information contained within it. For example when we get a phone call we can update the notes field with time/day/user and a quick note about what the customer has told us on the call. The 'Notes' field is shown on our main customer layout which could be on the screen for a few hours at times. If I did an autocalc when the layout is displayed the time would be out when the script is invoked.

                 The solution, based upon the Get commands you provided above works perfectly (see atttached)...

                 Many thanks for your help...

                 Rick.

            • 3. Re: Button (or Script) to insert username, time and date into field
              philmodjunk

                   Yes you will need to add more fields, and possibly a whole new table.

                   By keeping the data in separate fields, you gain the ability to sort and search your notes by date and by name in ways not possible when you insert multiple items of different data types into the same field.

                   In some cases, this method is used to record multiple notes into the same text field--which is even worse as you then lose a great deal of flexibility in how you can work with such data after it is entered. A related table of notes with at least 4 fields: Name, timestamp, note text and foreign key to parent table is many times more flexible and yet, if you set it up correctly on your layout offers very little change in the look and feel for your user.

                   And I make it a habit to avoid using script steps that start with "insert" unless that step is truly necessary. Those steps are much more vulnerable to "breaking" due to future layout modifications than using Set Field and it can also be used to insert a name and timestamp into your field--though I recommend against doing that.