Expand my Community achievements bar.

FORMCALC (or JS) Default date today with user override questions

Avatar

Former Community Member
I have a date field where if null, I want today to be inserted. If the user overrides the today date and saves the form, I want the user entered date to stay.



What I have in FORMCALC is:



if ($.isNull)

then

$.rawValue = num2date(date(), DateFmt(2))

endif



The first part works, it populates with today, and I can overrided the date. When I save and then reopen the form, the date is "0".



Any ideas here?
7 Replies

Avatar

Level 10
Hi Chris,



I tested your script and it worked perfectly in the Date field's calculate event.



Note sure what is going on???



Regards,



Niall

Avatar

Level 3

Hi Niall,

This is sort of related to this discussion. I have a form with two date fields - I want the user to select a date in the first field and then the second field populates the same date but it then able to be overridden by the user without this affecting the first date field. Is this possible, and how would it be done. I am fairly new to scripting and LiveCycle. Thanks for your help.

Avatar

Level 2

I realize this is an old post however, in the event someone else sees this post and is learning JS;

You add 2 date fields and on the 1st one under the exit event you add the following code:

      DateField2.formattedValue = this.formattedValue;

Best regards

Ian.

Avatar

Former Community Member
For some reason it was NOT working in the calculate event, I moved it to the form:ready event and it started working.



Thanks for the verification.

Avatar

Former Community Member
I'm having the same problem as described above but I am using JavaScript to reflect the current date:

var msNow = (new Date()).getTime();

var d1 = new Date(msNow);

this.rawValue = util.printd("mm/dd/yyyy", d1);



The user can override the current date and save the form, BUT when the form is reopened it will run again and insert the current date over the user entered date.



(I've tried several variations of "if (this.isNull)" to the above code which results in "01/00/0000" when opening the saved form --so it still doesn't retain the date entered by the user.)



Does anyone know what code I need to add to to keep the user entered date that was saved with the form? Or if there is a better way to make the date calendar default to today, allow user override and save that user entered date on the form?

Avatar

Level 10
You need an if...else to check to see if the field is empty, if empty input date, if not empty, retain current value.



Here's a javascript I use to generate a unique identifier based on the date and time the form is opened:



if (this.rawValue == null) {

var d = new Date();

//divide result by 1000 to get seconds and round off

this.rawValue = parseInt(d / 1000);

}

else {

this.rawValue = rawValue;

}



Formcalc I based it on:



if ($.rawValue==null)then

$.rawValue = [put your script here]

else $.rawValue

endif

Avatar

Former Community Member
Thank you so much! That was exactly the info I needed to resolve!!!

In case anyone needs it in the future, here's the JS:



if (this.rawValue == null){

var msNow = (new Date()).getTime();

var d1 = new Date(msNow);

this.rawValue = util.printd("mm/dd/yyyy", d1);

}

else {

this.rawValue = rawValue;

}