9 Replies Latest reply on Mar 22, 2011 1:12 PM by carrienmsd

    Date/Time driving me nuts.  How to set Time automatically?

    carrienmsd

      Ok ok.  Hope someone can help me out here!

       

      I tried this in Acrobat Pro first, but I dont know Javascript and so couldn't modify the "Call Date" script to get the Time instead.

       

      Fortunately, I also have Livecycle and everything looked so simple BUT it's not working.

       

      Let me explain what I'm trying to do.  My boss asked me to develop a log entry form in where after the user types in an entry and leaves the field then the time of the entry is automatically logged.  This field should be unalterable.

       

      I set up a Text Field (to act as the log entry form field).  I then set up a Date/Time field.  I went to Binding and changed it to Time.  I changed the Value to Read Only, and then the Pattern to h:MM A. 

       

      Set up the action- when user exits the text field, the Date/Time field value is inserted automatically.

       

      This works beautifully EXCEPT I only get the DATE!  I've tried Protected, Read Only (calculated) etc.  This requires a script to be called.... the very thing I hoped to avoid since I can't code.  RunTime worked somewhat-- but in the PDF itself, when the user exits the text field, the date AND time shows up, but if that field is clicked, the time is updated.  I don't want it updated.  My boss wants to see the time that the log entry was completed so it can't be changed by the user or updated.

       

      I hope I'm clear as to what I need.  Anybody can help?  Hope so!

       

      Thanks--

       

      -carrie

        • 1. Re: Date/Time driving me nuts.  How to set Time automatically?
          Worsty2 Level 1

          Test if the field is null before assigning the current date.

           

           

           

           

          // form1.page1.currentDate::ready:layout - (FormCalc, client)

           

           

           

          if (this.isNull) then

           

            $.rawValue = Concat(Num2Date(Date(), "MM/DD/YYYY"))

           

          endif

           

           

           

          Deborah

          • 2. Re: Date/Time driving me nuts.  How to set Time automatically?
            pguerett Level 6

            Here is an example .....you will need to write code on the exit event of the TextField that you want to lock. The corresponding Log Time field wil get set only if you enter a value.

             

            Hope that helps

            Paul

            • 3. Re: Date/Time driving me nuts.  How to set Time automatically?
              carrienmsd Level 1

              Paul, your file has exactly what I want!

               

              But I'd sure love to know how to do that.  I'll need to add more of those fields etc so knowing the underpinnings is a necessity. 

               

              I was right- the action I wanted was based on 'Calculated-Read Only' in the value setting.  However, how to add the script? 

              • 4. Re: Date/Time driving me nuts.  How to set Time automatically?
                carrienmsd Level 1

                Deborah,

                 

                Being the newbie that I am, I can't make sense of your answer.  I assume you mean to use FormCalc to create the script that the 'Calculated-Read Only' value setting will refer to?

                 

                 

                • 5. Re: Date/Time driving me nuts.  How to set Time automatically?
                  gkaiseril MVP & Adobe Community Professional

                  Are you creating your form in Acrobat or LiveCycle Designer. A little hare to tell with all of your posts.

                   

                  For Acrobat forms:

                   

                  You can get a lot of different information from the date object by changing the format string for the 'util.printd' method. See the reference George Johnson links to for the format string values that can change the displayed value.

                   

                   

                  // get new Date object
                  var d = new Date();

                  // format to h:MM tt
                  var sDate = util.printd("h:MM tt", d);

                  // insert date into form field
                  this.getField("todaysDate").value = sDate;

                   

                  h - hours without leading zero

                  MM - minutes with leading zero if necessary

                  tt - am or pm designator

                   

                  For LiveCycle Designer you can select the 'Custom' form tab and then the 'Current Date' field. Now change the script to:

                   

                  $.rawValue

                  = num2Time(time(), TimeFmt(1))

                   

                  More information about the time format is the 'Scripting Reference' under LiveCycle Designer's 'Help' menu option.

                   

                  For the field object, you can set the "Value" "Type:" option to "Calculated - Read Only". But if you use the predefined 'Current Date' field, this is already done for you.

                   

                  • 6. Re: Date/Time driving me nuts.  How to set Time automatically?
                    pguerett Level 6
                    1. Open my  form in Designer.
                    2. Highlight one of the fields that gets locked.
                    3. In the script editor (above the form design but below the menu items) in the top left is a dropdown labelled Show. This is a dropdown that shows all of the events that this object supports. Anything that has code will have an asterix beside it. In our case th eexit event will have code.Choose the exit event and code will appear in the script window.
                    4. Highlight all of the code including the if and endif statements (do not pick the 1st line that has form1.#subform .......). Copy this code to the clipboard
                    5. Now open your form. We need to change the default language to FormCalc instead of Javascript
                    6. Under th eFile/Form Properties/Deafults menu in teh middle of the screen make sure that the Default language is set to FormCalc and not Javascript and make sure that the Default Run At is set to Client (it shoudl be by default)
                    7. I assume that you are doing something similar where you have a field and the Log Time beside it.
                    8. Make sure each field and corresponding time set log field has a unique name.
                    9. Now kighlight the 1st field you want to lock down.
                    10. In the script editor choose the exit event (like we did before)
                    11. Place the cursor after the 1st line in teh script editor and paste the code that is in the clipboard into the script editor.
                    12. NOw we need to modify the script to point to your object names. I have pasted a version of the code below .....teh part in red is the name of my object ...you need to modify it to point to your object names. Thats it.

                      

                    if ($.rawValue <> null)then

                    Log1.rawValue

                    = Num2Time(Time(), "HH:MM:SS")

                    $.access

                    = "readOnly"

                    endif

                    • 7. Re: Date/Time driving me nuts.  How to set Time automatically?
                      carrienmsd Level 1

                      Strange, the text you mentioned is not showing up in red.  I checked in another broswer and it's not showing up either.  What was the name of your object? 

                      • 8. Re: Date/Time driving me nuts.  How to set Time automatically?
                        pguerett Level 6

                        It looks like the colour is not coming through ....

                         

                        The object is called Log1 and is at the beginning of the 2nd line.

                         

                        Paul

                        1 person found this helpful
                        • 9. Re: Date/Time driving me nuts.  How to set Time automatically?
                          carrienmsd Level 1

                          Got it working!!

                           

                          Thank you so much, Paul. 

                           

                          Also thanks to those of you who took the time to reply.  Really appreciate it.