Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using Timestamp

New Here ,
Jul 19, 2016 Jul 19, 2016

I am creating a form that behaves like a time clock. I have used the Mouse Up function with a field named Timestamp and it doesn't work. Should I expect this type of function to work with Adobe? I am a novice, but follow directions well. 

TOPICS
Acrobat SDK and JavaScript , Windows
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2016 Jul 19, 2016

We need a bit more information: What exactly are you doing in your mouse-up action? What is "this type of function"? If you want to learn about time and date support in Acrobat's JavaScript, take a look at this three part tutorial:

https://acrobatusers.com/tutorials/date_time_part1 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2016 Jul 19, 2016

I created a form. I added a text box so that the system can generate the

date and time and input the date and time into a the text box with one

click, so employees don't have to use an electronic time stamp machine.

Maybe my hopes are too high for an Adobe app. I copied the following into

the menu that allows me to customize the box (font size, placement, etc:

// Mouse UP script of a button

getField("timestamp1").value = util.printd("mm/dd/yyyy HH:MM", new Date());

Nothing happened.

I will review the link that you provided, but if Adobe, using Java Script,

can't do what I want, I don't need to go through the tutorial.

Thanks.

Claudia

On Tue, Jul 19, 2016 at 12:10 PM, Karl Heinz Kremer <

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2016 Jul 19, 2016

In that case, use the following script, it should fill in the data when the user clicks on the field:

event.target.value = util.printd("mm/dd/yyyy HH:MM", new Date());

However, this will require a few clicks to get the date into the field: You are triggering this off the mouse-up event. This means that you have to click on the field, and then click again outside of the field to actually see the value. It might be easier to have a button that fills in the date and time information (and in that case you can use the script that you've quoted).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2016 Jul 19, 2016

Thanks. It worked in the first box. When you have a box with the same

name, it adds the same information. the name of my text field is

"timestamp1" When I try to use "Timestamp2" for the next box nothing

happens.

On Tue, Jul 19, 2016 at 1:45 PM, Karl Heinz Kremer <forums_noreply@adobe.com

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2016 Jul 19, 2016

JavaScript is case sensitive, so make sure that Timestamp2 is the correct name. Without seeing the document, it's impossible to say what's going on. Are you getting any error messages on the JavaScript console (Ctrl-J or Cmd-J)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2016 Jul 19, 2016

The spelling is correct. If I duplicate the name of a text box in Adobe,

it will reproduce the same result again. Therefore, I have to name the

boxes as follow, textbox1, textbox2 , etc. Is there a way to give a

consecutive numbering scheme to the Timestamp functon?

On Tue, Jul 19, 2016 at 2:19 PM, Karl Heinz Kremer <forums_noreply@adobe.com

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2016 Jul 19, 2016

Fields with the same name will always have the same value. You'll need to rename one of them if you want it to have a unique value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2016 Jul 20, 2016

When I change the field name, Timestamp, to something else, it won't calculate the date and time in the field.  This is in response to the comment; fields with the same name will produce the same value.  Is the field name "Timestamp" triggering the response, or Java Script?  Or, are both required to produce a result? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2016 Jul 20, 2016

If you have two different fields with two different names, and you use my script (the one using "event.target.value") into each field as a mouse-up action, you should get the same result for both fields: The user clicks on a field, and clicks out of the field again and the field will be updated with the current date.

If you are using a button to trigger the filling of the field with the timestamp, you will have to use the correct field name in the "this.getField()" call.

So, depending on which solution you use, it's either the JavaScript alone that will update the field, or the combination of JavaScript and the correct field name.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2016 Jul 20, 2016

The java script is in the "run validation script." I removed the script from the "mouse up" entry area. The name of the field is "Timestamp."  No button is being used.  When I use the combination of the field name and the java script, I get a date and time.  When the field name is changed from "Timestamp", nothing appears in the field.  I want to use the java script to calculate a date and time for, time in, and time out, for 5 days. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2016 Jul 20, 2016

Should I add the name of the new field name in the parentheses to get a result when the name is changed.  For example, should the script indicate the following?  "this.getField(Timestamp2)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2016 Jul 20, 2016

I appreciate your patience on this issue.  If I want to use the java script without it being connected to a field name, which java script do I use?  My assumption is that if I don't use the script in conjunction with a field name, then I can use whatever field name I want, which should solve my problem. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2016 Jul 20, 2016

Can you share your file? If not, you can create a blank page with just the timestamp fields and the relevant scripts and share that. Based on your explanation, it's not clear why you see the behavior you've described.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2016 Jul 20, 2016

The file is attached. I left the script and the field names in place.

Thanks for all your support.

On Wed, Jul 20, 2016 at 10:19 AM, Karl Heinz Kremer <

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2016 Jul 20, 2016

You cannot attach files to a forums discussion (only images and videos). See here for instructions about how to use Adobe's Document Cloud to share a file: Share Documents via Adobe's Document Cloud - KHKonsulting LLC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2016 Jul 20, 2016

https://files.acrobat.com/a/preview/92280ee0-e803-4c04-86fe-5c8bff5902d7

On Wed, Jul 20, 2016 at 11:31 AM, Karl Heinz Kremer <

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2016 Jul 20, 2016

Claudia,

there are a number of problems with your form. First, by moving the script to the validation script, you are only running the script when the user actually modifies the field. You would have to actually enter some data (or remove something) to get an updated time stamp. By using the click handler (even though it requires two clicks or tabs), you get don't have to modify the field data in order for the script to run.

The second problem is that you are referring to the field using the "this.getField()" method - which in an event handler will not give you the correct behavior. That's why we can access the field data via "event.value" in e.g. a validation or a calculation script.

The third problem is that you are using the "Timestamp1" name in all your event handlers, regardless of the field that they should actually modify (this would be fixed by using "event.value" instead of the getField() method.

After seeing your form, here is what I would do: Stack two fields on top of each other, make the timestamp field read-only, and add a completely transparent button on top of it (or a button that says "click here to record time", and then remove the label afterwards, or use this text as the default text for your timestamp field). And then, have the button fill in the field value using the "getField()" method. You only have to make sure that the "stacking" of the fields is correct so that the button field is in front of the text field. See here for a sample document: http://khkonsulting.com/files/AUC/SetTimeStamp.pdf

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2016 Jul 20, 2016

Karl,

Should the script read "event.value = util.printd("mm/dd/yyyy HH:MM", new

Date());

If so, does this go into the validation area?

The field name reads: "Timestamp"? and this should be the name for all the

fields requesting time stamp information.

I tried to stack the button onto the Timestamp (read only) field. I even

named the button "click here to record time. It did not work.

Did you do it and did it work for you?

On Wed, Jul 20, 2016 at 12:14 PM, Karl Heinz Kremer <

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2016 Jul 20, 2016

Did you look at the sample document I linked to? You can download and inspect it to see exactly how I did this. The trick is to get the text field and the button in the right order. I do this by creating the text fields first, and then adding the buttons as the last step. In that case, I use the following script (of course adjusted for every related text field):

this.getField("Timestamp1").value = util.printd("mm/dd/yyyy HH:MM", new Date());

This would be used as the "mouse button up" action on the button field. There is no JavaScript you have to set for the text field, it's all done with this one line in the button script.

Every pair of button and text field need their own name. You can for example name the time stamp text fields "Timestamp1", "Timestamp2", and so on, and the corresponding buttons "SetTimestamp1", "SetTimestamp2", ... The actual names do not matter, what matters is that you use each name only once, and that you use the correct name of the corresponding time stamp field in the script that you install for the button.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 21, 2016 Jul 21, 2016
LATEST

Karl,

I was able to get the form to calculate the time in and time out. I have

not been able to get the button to work. I am working on it and will

advise when I am successful. Your last post was extremely helpful. Once I

get the button to overlay properly and work, I will have accomplished my

goal.

On Wed, Jul 20, 2016 at 4:15 PM, Karl Heinz Kremer <forums_noreply@adobe.com

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2016 Jul 20, 2016

When I change the field name, Timestamp, to something else, it won't calculate the date and time in the field.  This is in response to the comment; fields with the same name will produce the same value.  Is the field name "Timestamp" triggering the response, or Java Script?  Or, are both required to produce a result? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines