Date Range Reveal

Community Beginner ,
May 03, 2018

Copy link to clipboard

Copied

Hey everyone,

I would like to write a script that reveals a field only if an employee puts a particular date range in 2 fields.

Basically, there is Date_Field_1 and Date_Field_2. If an employee puts in a date range between the two which is shorter than 3 days, I'd like a certain field to show up. If they put in a date range between the two which is longer than 3 days, I'd like the field to be hidden.

I can reverse engineer scripts alright, I guess. But I have no idea how to write them on my own from scratch. Can anyone help?

TOPICS
Acrobat SDK and JavaScript

Views

103

Likes

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

Date Range Reveal

Community Beginner ,
May 03, 2018

Copy link to clipboard

Copied

Hey everyone,

I would like to write a script that reveals a field only if an employee puts a particular date range in 2 fields.

Basically, there is Date_Field_1 and Date_Field_2. If an employee puts in a date range between the two which is shorter than 3 days, I'd like a certain field to show up. If they put in a date range between the two which is longer than 3 days, I'd like the field to be hidden.

I can reverse engineer scripts alright, I guess. But I have no idea how to write them on my own from scratch. Can anyone help?

TOPICS
Acrobat SDK and JavaScript

Views

104

Likes

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
May 03, 2018 0
Adobe Community Professional ,
May 04, 2018

Copy link to clipboard

Copied

HI,

Something like the following should help

var curDoc = app.doc

var date1 = curDoc.getField("Date_Field_1");

var date2 = curDoc.getField("Date_Field_2");

// make them into dates, so we can do date maths on them - the field returns a string.

var actualDate1 = new Date ( date1.value);

var actualDate2 = new Date ( date2.value);

// this assumes date 2 is in the future, if it is the other way round you may need to change this line.

var dateChange = actualDate2 - actualDate1;

var millisec3Days = 259200000

// compare to 3 days

if ( dateChange >  millisec3Days )

{

    curDoc.getField ("Text4").hidden = false;

}

else

{

    curDoc.getField ("Text4").hidden = true;

}

Regards

Malcolm

Likes

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
Reply
Loading...
May 04, 2018 0
Adobe Community Professional ,
May 04, 2018

Copy link to clipboard

Copied

Is there any requirement that date 1 must be before date 2?

Do you want the validation to be performed as the user enter the dates into each field or by using a button.?

Likes

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
Reply
Loading...
May 04, 2018 0
BarlaeDC LATEST
Adobe Community Professional ,
May 04, 2018

Copy link to clipboard

Copied

I just made that assumption to keep the code cleaner, the dates could be either way round would just need to code to allow for a possible negative value. if you have a negative value the the "if ( dateChange > millisec3Days )" wouldn't catch the 3 days elapsed days correctly.

Likes

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
Reply
Loading...
May 04, 2018 0