Expand my Community achievements bar.

Date and Time Stamp Question

Avatar

Level 1

I have a payroll form that has a section for a submitted on date that is protected. 

I need the form to default to the current date/time when the user opens it (and ultimately emails it to our Administrative folks) but when our Administrative folks open it up the date needs to still show the date the user submitted it.

I have tried several different methods in order to make this happen, to no avail. 

Anyone have any solutions?!?!??!    TIA

3 Replies

Avatar

Level 7

That is a pain isn't it. I have come across this before.

I add some logic to the form. The initial form when created must have a blank date time field

To the datetimefield initialisation javascript event add:

if(this.rawValue == null) //if the date time field is empty, get the current date

{

this.resolveNode("$").rawValue = util.printd("yyyy-mm-dd", new Date());

}

else //if it already contains a value, dont do anything.

{}

What will happen then is that if the datetimefield already contains a date, the initialisation event wont do anything, but if it is blank upon opening the form. it will get the current date.

Avatar

Level 1

Thank you!  Now if I wanted to add the time as well, where would that go???

TIA

Avatar

Level 7

You can choose to display the time in a separate 'time' field or concatenate it into the same field as the date.

Example:

this.resolveNode("$").rawValue = util.printd("HH:MM:ss", new Date()); //in your dateTimeField, this will display the time with seconds and leading zeros. eg: 14:08:37

If you wish to have the date and time in the same DateTimeField:

//show the date and time separated with a space.

this.resolveNode("$").rawValue = util.printd("dd-mm-yyyy", new Date()) + " " + util.printd("HH:MM:ss", new Date());

This is displayed

1405459_pastedImage_0.png

Please mark as correct if satisfied. Thanks