Skip to main content
Inspiring
March 6, 2021
Answered

Phantom Date remaining in calculated dateObject despite clearing and resetting form

  • March 6, 2021
  • 5 replies
  • 4358 views

placed in dateObject BirthDate custom calc script
var BirthDay = this.getField("CustomerDOB").value
var BirthDayMonth = util.scand("mm/dd/yyyy", BirthDay.slice(0,6));
event.value = util.printd("mm/dd/yyyy", BirthDayMonth);}

 

When I enter the actual birthdate in CustomerDOB dateObject, it keeps the day and month values but brings the year current, and displays this date value in the BirthDate dateObject. Problem is when I clear form or use the reset button the current date is populated into BirthDate dateObject and this current date remains. I've looked at similar posts and their solutions but nothing seems to work. How do I get rid of it???????? I attached the file so you can see the setup- thanks in advance

This topic has been closed for replies.
Correct answer try67

Yes, because code is not meant for that format, if you change slice(0,4) it will work,It's not for 1/1/1980 format.

Well if you want to be tehnical use your code and enter 02/29/1980 for example


Yes, because code is not meant for that format


By @Asim123

 

Yes, and that's exactly the problem with it. You have to take into account things the end-user can do, even if they're not what you intend them to do... As long as they can do it, I can assure you they will do it.

 

Well if you want to be tehnical use your code and enter 02/29/1980 for example


By @Asim123

 

That is an extremely narrow issue, and a very unlikely one, but you're right that technically it will produce an incorrect result. I've adjusted the script to take care of that, too:

 

var BirthDayString = this.getField("CustomerDOB").valueAsString;
if (BirthDayString=="") event.value = ""; 
else {
	var BirthDay = util.scand("mm/dd/yyyy", BirthDayString);
	BirthDay.setFullYear(new Date().getFullYear());
	event.value = util.printd("mm/dd/yyyy", BirthDay);
}

5 replies

Bernd Alheit
Community Expert
Community Expert
March 7, 2021

The phantom date is the result of the calculation at this field.

Inspiring
March 7, 2021

yes, it's populating the system's clock date as default value in the BirthDate dateObject field when nothing is user-entered into the CustomerDOB dateObject field. Thank you Bernd for your response! 

try67
Community Expert
Community Expert
March 7, 2021

Your code doesn't make much sense. Please explain what you're trying to achieve, first.

Inspiring
March 7, 2021

customer enters their birth date in CustomerDOB dateObject field. A custom calculation script in the BirthDate dateObject field splices the month and day of the user-entered date string and combines it with the current year. For example, the user enters 11/02/1967 in the CustomerDOB dateObjectField and 11/02/2021 is calculated as the value and displayed in the BirthDate dateObject field. I then intend to use this 'currrent' BirthDate value in subsequent calculations to obtain values for different periods of time, applying these resultant time periods to determine fees owed by the customer. Everyday in my job I see how language barriers compound the fear factor of dealing with gov. bureaucracy. My goal is to set up a simple user interface that completes all the appropiate gov forms correctly, avoiding confusion and delays for our customers.  Yes, there are still some of us that consider it a privilege to work for the public!

try67
Community Expert
Community Expert
March 7, 2021

OK, I see. Use this script, then:

 

var BirthDayString = this.getField("CustomerDOB").valueAsString;
if (BirthDayString=="") event.value = ""; 
else {
	var BirthDay = util.scand("mm/dd/yyyy", BirthDayString);
	event.value = util.printd("mm/dd/", BirthDay) + new Date().getFullYear();
}
Nesa Nurani
Community Expert
Community Expert
March 7, 2021

Try  this:

var BirthDay = this.getField("CustomerDOB").value;
if(BirthDay == "")
event.value = "";
else {
var BirthDayMonth = util.scand("mm/dd/yyyy", BirthDay.slice(0,6));
event.value = util.printd("mm/dd/yyyy", BirthDayMonth);}

 

Inspiring
March 7, 2021

Hey Nesa; just wanted to say thank you for your response- it worked! But I also wanted to bring your attention to try67's response regarding the splice comment. Something to keep in mind- thank you Nesa and Be Safe!!!

Inspiring
March 7, 2021

ok I realize by not specifying date in CustomerDOB it autopopulates using the system's current date/time settings. Is there a way I can do this? I tried unsuccessively

 

if (CustomerDOB === "") {event.value = "";}

else if {

var BirthDay = this.getField("CustomerDOB").valueAsString;
var BirthDayMonth = util.scand("mm/dd/yyyy", BirthDay.slice(0,6));
event.value = util.printd("mm/dd/yyyy", BirthDayMonth);

}

 

Legend
March 7, 2021

"if (CustomerDOB === "") {event.value = "";}

else if {

var BirthDay = this.getField("CustomerDOB").valueAsString;
var BirthDayMonth = util.scand("mm/dd/yyyy", BirthDay.slice(0,6));
event.value = util.printd("mm/dd/yyyy", BirthDayMonth);

}"

This code is obviously incomplete (or wrong) since we don't know how you set CustomerDOB. Also that's not what an if statement looks like. Did you check the console for errors?

Inspiring
March 7, 2021

CustomerDOB is user entered with mm/dd/yyyy format selected on the properties' of the dateObject field. All of the dateObject fields are set this way.

Inspiring
March 6, 2021

using .valueAsString also has the same result