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

Using date to determine value in a field

New Here ,
Dec 06, 2020 Dec 06, 2020

Copy link to clipboard

Copied

Hi,

I am wanting to create a script to select a particular value, based on date.

Specifically, the selection will be based on the date occuring on or prior to 01/01/1996.  The date field is "DOB"  The field I want to autofill is named "CourseFee". 

 

I have two calculated fields and want to be able to select and autofill the "CourseFee" field based on the date.

If the date is prior to the one above, I want a value (Under25) to autofill.  If the date is later than the one above, I want the value (Over25) to autofill.

Is this doable?

TOPICS
Acrobat SDK and JavaScript

Views

133

Translate

Translate

Report

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
Enthusiast ,
Dec 07, 2020 Dec 07, 2020

Copy link to clipboard

Copied

Under25 and Over25 are younger or older then 25years?

Why select 01/01/1996? If someone is born 01/01/1996 in one month your calculation will be wrong they would be Over25 and your calculation will show it's Under25.

 

Votes

Translate

Translate

Report

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 ,
Dec 07, 2020 Dec 07, 2020

Copy link to clipboard

Copied

LATEST

First of all, as mentioned, the age depends not only on the DOB, but also on the current time... But what you described can be achieved using the following code as the custom calculation script of "CourseFee":

 

var dobString = this.getField("DOB").valueAsString;
if (dobString=="") event.value = "";
else {
	var dob = util.scand("mm/dd/yyyy", dobString);
	var cutOffDate = new Date(1996, 0, 1);
	event.value = (dob.getTime()>=cutOffDate.getTime()) ? "Under25" : "Over25";
}

Votes

Translate

Translate

Report

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