Skip to main content
Participating Frequently
June 25, 2018
Question

How to autofill date and time based on a previous input?

  • June 25, 2018
  • 3 replies
  • 890 views

Hello,

I would like to know how to automate date and time (military time) based on a previous input. Please refer to the image below.

So, I would like to automate it so that when the shift supervisor has filled out the signature field, both the date and time field will be automatically filled. How can I do that? Please help! 

This topic has been closed for replies.

3 replies

mbabu001Author
Participating Frequently
June 26, 2018

Wow, thank you very much. This is exactly what I needed.

mbabu001Author
Participating Frequently
June 26, 2018

try67

I was somehow able to get it to work using the following script on the "signature" field:

var timeField = this.getField("Time");
timeField.value = util.printd("HH:MM", new Date());

var dateField = this.getField("Date");
dateField.value = util.printd("mm/dd/yyyy", new Date());

However, the problem I have with this is code is that every time the signature field is simply clicked on, the date and time is updates automatically. Even without putting any information on the signature field, the data and time gets updated. I would like to make it so that some sort of information has to be in the "signature" field for the date and time to be update. And, I would like to make sure the date and time field stay fixed once the "signature" field has been filled. Because, as of now, simply clicking on the signature filed updates the date and time automatically.

So, for example:

          Once "John Doe" was put his initials in the signature field, the date and time will be automatically updates and will remain fixed. Only when ALL the information in the signature has been erased can be date and time field change.

is there a way I can do this?

try67
Community Expert
Community Expert
June 26, 2018

You're on the right path. I think you placed the code in an incorrect location, though. Move it to be the signature field's custom Validation script, and use this version of it:

var timeField = this.getField("Time");

var dateField = this.getField("Date");

if (event.value=="") {

    timeField.value = "";

    dateField.value = "";

} else {  

    timeField.value = util.printd("HH:MM", new Date());  

    dateField.value = util.printd("mm/dd/yyyy", new Date());

}

try67
Community Expert
Community Expert
June 25, 2018

What kind of field is your "signature" field? If it's a real Digital Signature then it will contain the current date and time automatically, although it doesn't look like it is. If it's just a text field you can use the field's custom validation script to populate the other fields.